diff --git a/.gitignore b/.gitignore
index 8e249491..11c72867 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
/source/node_modules
/demo/bin-debug
/demo/bin-release
+/.idea
+/.vscode
+/demo_wxgame
diff --git a/.vscode/launch.json b/.vscode/launch.json
deleted file mode 100644
index 7b7a8605..00000000
--- a/.vscode/launch.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- // 使用 IntelliSense 了解相关属性。
- // 悬停以查看现有属性的描述。
- // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
- "version": "0.2.0",
- "configurations": [
- {
- "type": "pwa-chrome",
- "request": "launch",
- "name": "Launch Chrome against localhost",
- "url": "http://localhost:8080",
- "webRoot": "${workspaceFolder}"
- }
- ]
-}
\ No newline at end of file
diff --git a/README.md b/README.md
index 84a9434b..7ad9c452 100644
--- a/README.md
+++ b/README.md
@@ -3,26 +3,11 @@
[](https://lgtm.com/projects/g/esengine/egret-framework/context:javascript)
-```
-[](https://lgtm.com/projects/g/esengine/egret-framework/context:javascript)
-```
+这是一套用于egret的游戏框架,里面包含ECS框架用于管理场景实体,一些常用2D碰撞检测及A*寻路。如果您还需要包含其他的AI系统可以查看作者其他库(行为树、简易FSM、实用AI)。
-这是一套用于egret的游戏框架,里面包含ECS框架用于管理场景实体,MVC框架用于管理ui界面(fairygui),一些常用2D碰撞检测及A*寻路。如果您还需要包含其他的AI系统可以查看作者其他库(行为树、简易FSM、实用AI)。
-
-## 当前版本功能
+## 版本计划功能
- [x] 简易ECS框架
-- [x] A*寻路(AStar)
-- [x] 常用碰撞检测
-- [x] 数学库
- - [x] 简易矩阵类
- - [x] 简易2d 向量类
- - [x] 掩码实用类
-- [x] BreadthFirst 寻路算法
-- [x] Dijkstra 寻路算法
-- [x] 事件处理器
-
-- [x] ECS
- [x] 组件列表
- [x] 碰撞组件
- [x] 移动组件
@@ -38,9 +23,37 @@
- [x] 系统列表
- [x] 被动系统
- [x] 协调系统
-- [ ] 数学库
- - [ ] 贝塞尔曲线
- - [ ] 快速随机数类
+- [x] A*寻路(AStar)
+- [x] 常用碰撞检测
+- [x] 数学库
+ - [x] 简易矩阵类
+ - [x] 简易2d 向量类
+ - [x] 掩码实用类
+ - [x] 贝塞尔曲线
+ - [x] 快速随机数类
+- [x] BreadthFirst 寻路算法
+- [x] Dijkstra 寻路算法
+- [x] 事件处理器
+
+## 关于egret用ecs框架(typescript/javascript)
+ecs 是功能强大的实体组件系统。typescript与其他语言不同,因此我对ecs的设计尽可能的支持typescript特性。虽然ecs拥有标准实体组件系统,但在细节上有很大不同。创建标准ecs通常处于原始速度、缓存位置和其他性能原因。使用typescript,我们没有struct,因为没有必要匹配标准实体组件系统的设计方式,因为我们对内存布局没有那种控制。
+
+ecs更灵活,可以更好的集中、组织、排序和过滤游戏中的对象。ecs让您拥有轻量级实体和组件,这些组件可以由系统批量处理。
+例如,您在制作一个射手,您可能会有几十到几百个子弹,这些作为轻量级实体由系统批量处理。
+
+所以ecs在设计当中拥有四种重要类型:世界(Scene),过滤器(Matcher),系统(System)和实体(Entity)
+
+## 世界(Scene)
+Scene是ecs包含系统和实体最外面的容器。
+
+## 实体(Entity)
+实体只由系统处理。
+
+## 组件(Component)
+组件应该只包含数据而没有逻辑代码。对数据进行逻辑是系统的工作。
+
+## 系统(System)
+ecs中的系统会不断的更新实体。系统使用过滤器选择某些实体,然后仅更新那些选择的实体。
## 作者其他库(egret)
diff --git a/_config.yml b/_config.yml
new file mode 100644
index 00000000..c7418817
--- /dev/null
+++ b/_config.yml
@@ -0,0 +1 @@
+theme: jekyll-theme-slate
\ No newline at end of file
diff --git a/demo/.idea/.gitignore b/demo/.idea/.gitignore
new file mode 100644
index 00000000..e7e9d11d
--- /dev/null
+++ b/demo/.idea/.gitignore
@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml
diff --git a/demo/.idea/demo.iml b/demo/.idea/demo.iml
new file mode 100644
index 00000000..c956989b
--- /dev/null
+++ b/demo/.idea/demo.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/.idea/misc.xml b/demo/.idea/misc.xml
new file mode 100644
index 00000000..28a804d8
--- /dev/null
+++ b/demo/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/.idea/modules.xml b/demo/.idea/modules.xml
new file mode 100644
index 00000000..c95e899e
--- /dev/null
+++ b/demo/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/.idea/vcs.xml b/demo/.idea/vcs.xml
new file mode 100644
index 00000000..6c0b8635
--- /dev/null
+++ b/demo/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts
index a8d146ad..f8cf463e 100644
--- a/demo/libs/framework/framework.d.ts
+++ b/demo/libs/framework/framework.d.ts
@@ -1,1058 +1,1848 @@
declare interface Array {
- findIndex(predicate: Function): number;
- any(predicate: Function): boolean;
- firstOrDefault(predicate: Function): T;
- find(predicate: Function): T;
- where(predicate: Function): Array;
- count(predicate: Function): number;
- findAll(predicate: Function): Array;
- contains(value: any): boolean;
- removeAll(predicate: Function): void;
- remove(element: any): boolean;
- removeAt(index: any): void;
- removeRange(index: any, count: any): void;
+ findIndex(predicate: (c: T) => boolean): number;
+ any(predicate: (c: T) => boolean): boolean;
+ firstOrDefault(predicate: (c: T) => boolean): T;
+ find(predicate: (c: T) => boolean): T;
+ where(predicate: (c: T) => boolean): Array;
+ count(predicate: (c: T) => boolean): number;
+ findAll(predicate: (c: T) => boolean): Array;
+ contains(value: T): boolean;
+ removeAll(predicate: (c: T) => boolean): void;
+ remove(element: T): boolean;
+ removeAt(index: number): void;
+ removeRange(index: number, count: number): void;
select(selector: Function): Array;
orderBy(keySelector: Function, comparer: Function): Array;
orderByDescending(keySelector: Function, comparer: Function): Array;
groupBy(keySelector: Function): Array;
- sum(selector: any): any;
-}
-declare class PriorityQueueNode {
- priority: number;
- insertionIndex: number;
- queueIndex: number;
-}
-declare class AStarPathfinder {
- static search(graph: IAstarGraph, start: T, goal: T): T[];
- private static hasKey;
- private static getKey;
- static recontructPath(cameFrom: Map, start: T, goal: T): T[];
-}
-declare class AStarNode extends PriorityQueueNode {
- data: T;
- constructor(data: T);
-}
-declare class AstarGridGraph implements IAstarGraph {
- dirs: Vector2[];
- walls: Vector2[];
- weightedNodes: Vector2[];
- defaultWeight: number;
- weightedNodeWeight: number;
- private _width;
- private _height;
- private _neighbors;
- constructor(width: number, height: number);
- isNodeInBounds(node: Vector2): boolean;
- isNodePassable(node: Vector2): boolean;
- search(start: Vector2, goal: Vector2): Vector2[];
- getNeighbors(node: Vector2): Vector2[];
- cost(from: Vector2, to: Vector2): number;
- heuristic(node: Vector2, goal: Vector2): number;
-}
-interface IAstarGraph {
- getNeighbors(node: T): Array;
- cost(from: T, to: T): number;
- heuristic(node: T, goal: T): any;
-}
-declare class PriorityQueue {
- private _numNodes;
- private _nodes;
- private _numNodesEverEnqueued;
- constructor(maxNodes: number);
- clear(): void;
- readonly count: number;
- contains(node: T): boolean;
- enqueue(node: T, priority: number): void;
- dequeue(): T;
- remove(node: T): void;
- isValidQueue(): boolean;
- private onNodeUpdated;
- private cascadeDown;
- private cascadeUp;
- private swap;
- private hasHigherPriority;
-}
-declare class BreadthFirstPathfinder {
- static search(graph: IUnweightedGraph, start: T, goal: T): T[];
- private static hasKey;
-}
-interface IUnweightedGraph {
- getNeighbors(node: T): T[];
-}
-declare class UnweightedGraph implements IUnweightedGraph {
- edges: Map;
- addEdgesForNode(node: T, edges: T[]): this;
- getNeighbors(node: T): T[];
-}
-declare class Vector2 {
- x: number;
- y: number;
- private static readonly unitYVector;
- private static readonly unitXVector;
- private static readonly unitVector2;
- private static readonly zeroVector2;
- static readonly zero: Vector2;
- static readonly one: Vector2;
- static readonly unitX: Vector2;
- static readonly unitY: Vector2;
- constructor(x?: number, y?: number);
- static add(value1: Vector2, value2: Vector2): Vector2;
- static divide(value1: Vector2, value2: Vector2): Vector2;
- static multiply(value1: Vector2, value2: Vector2): Vector2;
- static subtract(value1: Vector2, value2: Vector2): Vector2;
- normalize(): void;
- length(): number;
- round(): Vector2;
- static normalize(value: Vector2): Vector2;
- static dot(value1: Vector2, value2: Vector2): number;
- static distanceSquared(value1: Vector2, value2: Vector2): number;
- static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2;
- static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
- static transform(position: Vector2, matrix: Matrix2D): Vector2;
- static distance(value1: Vector2, value2: Vector2): number;
- static negate(value: Vector2): Vector2;
-}
-declare class UnweightedGridGraph implements IUnweightedGraph {
- private static readonly CARDINAL_DIRS;
- private static readonly COMPASS_DIRS;
- walls: Vector2[];
- private _width;
- private _hegiht;
- private _dirs;
- private _neighbors;
- constructor(width: number, height: number, allowDiagonalSearch?: boolean);
- isNodeInBounds(node: Vector2): boolean;
- isNodePassable(node: Vector2): boolean;
- getNeighbors(node: Vector2): Vector2[];
- search(start: Vector2, goal: Vector2): Vector2[];
-}
-interface IWeightedGraph {
- getNeighbors(node: T): T[];
- cost(from: T, to: T): number;
-}
-declare class WeightedGridGraph implements IWeightedGraph {
- static readonly CARDINAL_DIRS: Vector2[];
- private static readonly COMPASS_DIRS;
- walls: Vector2[];
- weightedNodes: Vector2[];
- defaultWeight: number;
- weightedNodeWeight: number;
- private _width;
- private _height;
- private _dirs;
- private _neighbors;
- constructor(width: number, height: number, allowDiagonalSearch?: boolean);
- isNodeInBounds(node: Vector2): boolean;
- isNodePassable(node: Vector2): boolean;
- search(start: Vector2, goal: Vector2): Vector2[];
- getNeighbors(node: Vector2): Vector2[];
- cost(from: Vector2, to: Vector2): number;
-}
-declare class WeightedNode extends PriorityQueueNode {
- data: T;
- constructor(data: T);
-}
-declare class WeightedPathfinder {
- static search(graph: IWeightedGraph, start: T, goal: T): T[];
- private static hasKey;
- private static getKey;
- static recontructPath(cameFrom: Map, start: T, goal: T): T[];
-}
-declare class DebugDefaults {
- static verletParticle: number;
- static verletConstraintEdge: number;
-}
-declare abstract class Component extends egret.DisplayObjectContainer {
- entity: Entity;
- private _enabled;
- updateInterval: number;
- userData: any;
- enabled: boolean;
- setEnabled(isEnabled: boolean): this;
- initialize(): void;
- onAddedToEntity(): void;
- onRemovedFromEntity(): void;
- onEnabled(): void;
- onDisabled(): void;
- update(): void;
- debugRender(): void;
- onEntityTransformChanged(comp: TransformComponent): void;
- registerComponent(): void;
- deregisterComponent(): void;
-}
-declare class Entity extends egret.DisplayObjectContainer {
- private static _idGenerator;
- name: string;
- readonly id: number;
- scene: Scene;
- readonly components: ComponentList;
- private _updateOrder;
- private _enabled;
- _isDestoryed: boolean;
- private _tag;
- componentBits: BitSet;
- readonly isDestoryed: boolean;
- position: Vector2;
- scale: Vector2;
- rotation: number;
- enabled: boolean;
- setEnabled(isEnabled: boolean): this;
- tag: number;
- readonly stage: egret.Stage;
- constructor(name: string);
- updateOrder: number;
- roundPosition(): void;
- setUpdateOrder(updateOrder: number): this;
- setTag(tag: number): Entity;
- attachToScene(newScene: Scene): void;
- detachFromScene(): void;
- addComponent(component: T): T;
- hasComponent(type: any): boolean;
- getOrCreateComponent(type: T): T;
- getComponent(type: any): T;
- getComponents(typeName: string | any, componentList?: any): any;
- private onEntityTransformChanged;
- removeComponentForType(type: any): boolean;
- removeComponent(component: Component): void;
- removeAllComponents(): void;
- update(): void;
- onAddedToScene(): void;
- onRemovedFromScene(): void;
- destroy(): void;
-}
-declare enum TransformComponent {
- rotation = 0,
- scale = 1,
- position = 2
-}
-declare class Scene extends egret.DisplayObjectContainer {
- camera: Camera;
- readonly entities: EntityList;
- readonly renderableComponents: RenderableComponentList;
- readonly content: ContentManager;
- enablePostProcessing: boolean;
- private _renderers;
- private _postProcessors;
- private _didSceneBegin;
- readonly entityProcessors: EntityProcessorList;
- constructor();
- createEntity(name: string): Entity;
- addEntity(entity: Entity): Entity;
- destroyAllEntities(): void;
- findEntity(name: string): Entity;
- addEntityProcessor(processor: EntitySystem): EntitySystem;
- removeEntityProcessor(processor: EntitySystem): void;
- getEntityProcessor(): T;
- addRenderer(renderer: T): T;
- getRenderer(type: any): T;
- removeRenderer(renderer: Renderer): void;
- begin(): void;
- end(): void;
- protected onStart(): Promise;
- protected onActive(): void;
- protected onDeactive(): void;
- protected unload(): void;
- update(): void;
- postRender(): void;
- render(): void;
- addPostProcessor(postProcessor: T): T;
-}
-declare class SceneManager {
- private static _scene;
- private static _nextScene;
- static sceneTransition: SceneTransition;
- static stage: egret.Stage;
- constructor(stage: egret.Stage);
- static scene: Scene;
- static initialize(stage: egret.Stage): void;
- static update(): void;
- static render(): void;
- static startSceneTransition(sceneTransition: T): T;
-}
-declare class Camera extends Component {
- private _zoom;
- private _origin;
- private _minimumZoom;
- private _maximumZoom;
- private _position;
- followLerp: number;
- deadzone: Rectangle;
- focusOffset: Vector2;
- mapLockEnabled: boolean;
- mapSize: Vector2;
- targetEntity: Entity;
- private _worldSpaceDeadZone;
- private _desiredPositionDelta;
- private _targetCollider;
- cameraStyle: CameraStyle;
- zoom: number;
- minimumZoom: number;
- maximumZoom: number;
- origin: Vector2;
- position: Vector2;
- x: number;
- y: number;
- constructor();
- onSceneSizeChanged(newWidth: number, newHeight: number): void;
- setMinimumZoom(minZoom: number): Camera;
- setMaximumZoom(maxZoom: number): Camera;
- setZoom(zoom: number): Camera;
- setRotation(rotation: number): Camera;
- setPosition(position: Vector2): this;
- follow(targetEntity: Entity, cameraStyle?: CameraStyle): void;
- update(): void;
- private clampToMapSize;
- private updateFollow;
-}
-declare enum CameraStyle {
- lockOn = 0,
- cameraWindow = 1
-}
-declare class ComponentPool {
- private _cache;
- private _type;
- constructor(typeClass: any);
- obtain(): T;
- free(component: T): void;
-}
-declare abstract class PooledComponent extends Component {
- abstract reset(): any;
-}
-declare abstract class RenderableComponent extends PooledComponent implements IRenderable {
- private _isVisible;
- protected _areBoundsDirty: boolean;
- protected _bounds: Rectangle;
- protected _localOffset: Vector2;
- color: number;
- readonly width: number;
- readonly height: number;
- isVisible: boolean;
- readonly bounds: Rectangle;
- protected getWidth(): number;
- protected getHeight(): number;
- protected onBecameVisible(): void;
- protected onBecameInvisible(): void;
- abstract render(camera: Camera): any;
- isVisibleFromCamera(camera: Camera): boolean;
-}
-declare class Mesh extends RenderableComponent {
- private _mesh;
- constructor();
- setTexture(texture: egret.Texture): Mesh;
- onAddedToEntity(): void;
- onRemovedFromEntity(): void;
- render(camera: Camera): void;
- reset(): void;
-}
-declare class SpriteRenderer extends RenderableComponent {
- private _sprite;
- protected bitmap: egret.Bitmap;
- sprite: Sprite;
- setSprite(sprite: Sprite): SpriteRenderer;
- setColor(color: number): SpriteRenderer;
- isVisibleFromCamera(camera: Camera): boolean;
- render(camera: Camera): void;
- onRemovedFromEntity(): void;
- reset(): void;
-}
-declare class TiledSpriteRenderer extends SpriteRenderer {
- protected sourceRect: Rectangle;
- protected leftTexture: egret.Bitmap;
- protected rightTexture: egret.Bitmap;
- scrollX: number;
- scrollY: number;
- constructor(sprite: Sprite);
- render(camera: Camera): void;
-}
-declare class ScrollingSpriteRenderer extends TiledSpriteRenderer {
- scrollSpeedX: number;
- scroolSpeedY: number;
- private _scrollX;
- private _scrollY;
- update(): void;
-}
-declare class Sprite {
- texture2D: egret.Texture;
- readonly sourceRect: Rectangle;
- readonly center: Vector2;
- origin: Vector2;
- readonly uvs: Rectangle;
- constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2);
-}
-declare class SpriteAnimation {
- readonly sprites: Sprite[];
- readonly frameRate: number;
- constructor(sprites: Sprite[], frameRate: number);
-}
-declare class SpriteAnimator extends SpriteRenderer {
- onAnimationCompletedEvent: Function;
- speed: number;
- animationState: State;
- currentAnimation: SpriteAnimation;
- currentAnimationName: string;
- currentFrame: number;
- readonly isRunning: boolean;
- private _animations;
- private _elapsedTime;
- private _loopMode;
- constructor(sprite?: Sprite);
- addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator;
- play(name: string, loopMode?: LoopMode): void;
- isAnimationActive(name: string): boolean;
- pause(): void;
- unPause(): void;
- stop(): void;
- update(): void;
-}
-declare enum LoopMode {
- loop = 0,
- once = 1,
- clampForever = 2,
- pingPong = 3,
- pingPongOnce = 4
-}
-declare enum State {
- none = 0,
- running = 1,
- paused = 2,
- completed = 3
-}
-interface ITriggerListener {
- onTriggerEnter(other: Collider, local: Collider): any;
- onTriggerExit(other: Collider, local: Collider): any;
-}
-declare class Mover extends Component {
- private _triggerHelper;
- onAddedToEntity(): void;
- calculateMovement(motion: Vector2): {
- collisionResult: CollisionResult;
- motion: Vector2;
- };
- applyMovement(motion: Vector2): void;
- move(motion: Vector2): CollisionResult;
-}
-declare abstract class Collider extends Component {
- shape: Shape;
- physicsLayer: number;
- isTrigger: boolean;
- registeredPhysicsBounds: Rectangle;
- shouldColliderScaleAndRotateWithTransform: boolean;
- collidesWithLayers: number;
- _localOffsetLength: number;
- protected _isParentEntityAddedToScene: any;
- protected _colliderRequiresAutoSizing: any;
- protected _localOffset: Vector2;
- protected _isColliderRegistered: any;
- readonly bounds: Rectangle;
- localOffset: Vector2;
- setLocalOffset(offset: Vector2): void;
- registerColliderWithPhysicsSystem(): void;
- unregisterColliderWithPhysicsSystem(): void;
- overlaps(other: Collider): any;
- collidesWith(collider: Collider, motion: Vector2): CollisionResult;
- onAddedToEntity(): void;
- onRemovedFromEntity(): void;
- onEnabled(): void;
- onDisabled(): void;
- onEntityTransformChanged(comp: TransformComponent): void;
-}
-declare class BoxCollider extends Collider {
- width: number;
- setWidth(width: number): BoxCollider;
- height: number;
- setHeight(height: number): void;
- constructor();
- setSize(width: number, height: number): this;
-}
-declare class EntitySystem {
- private _scene;
- private _entities;
- private _matcher;
- readonly matcher: Matcher;
- scene: Scene;
- constructor(matcher?: Matcher);
- initialize(): void;
- onChanged(entity: Entity): void;
- add(entity: Entity): void;
- onAdded(entity: Entity): void;
- remove(entity: Entity): void;
- onRemoved(entity: Entity): void;
- update(): void;
- lateUpdate(): void;
- protected begin(): void;
- protected process(entities: Entity[]): void;
- protected lateProcess(entities: Entity[]): void;
- protected end(): void;
-}
-declare abstract class EntityProcessingSystem extends EntitySystem {
- constructor(matcher: Matcher);
- abstract processEntity(entity: Entity): any;
- lateProcessEntity(entity: Entity): void;
- protected process(entities: Entity[]): void;
- protected lateProcess(entities: Entity[]): void;
-}
-declare abstract class PassiveSystem extends EntitySystem {
- onChanged(entity: Entity): void;
- protected process(entities: Entity[]): void;
-}
-declare abstract class ProcessingSystem extends EntitySystem {
- onChanged(entity: Entity): void;
- protected process(entities: Entity[]): void;
- abstract processSystem(): any;
-}
-declare class BitSet {
- private static LONG_MASK;
- private _bits;
- constructor(nbits?: number);
- and(bs: BitSet): void;
- andNot(bs: BitSet): void;
- cardinality(): number;
- clear(pos?: number): void;
- private ensure;
- get(pos: number): boolean;
- intersects(set: BitSet): boolean;
- isEmpty(): boolean;
- nextSetBit(from: number): number;
- set(pos: number, value?: boolean): void;
-}
-declare class ComponentList {
- private _entity;
- private _components;
- private _componentsToAdd;
- private _componentsToRemove;
- private _tempBufferList;
- constructor(entity: Entity);
- readonly count: number;
- readonly buffer: Component[];
- add(component: Component): void;
- remove(component: Component): void;
- removeAllComponents(): void;
- deregisterAllComponents(): void;
- registerAllComponents(): void;
- updateLists(): void;
- onEntityTransformChanged(comp: TransformComponent): void;
- private handleRemove;
- getComponent(type: any, onlyReturnInitializedComponents: boolean): T;
- getComponents(typeName: string | any, components?: any): any;
- update(): void;
-}
-declare class ComponentTypeManager {
- private static _componentTypesMask;
- static add(type: any): void;
- static getIndexFor(type: any): number;
-}
-declare class EntityList {
- scene: Scene;
- private _entitiesToRemove;
- private _entitiesToAdded;
- private _tempEntityList;
- private _entities;
- private _entityDict;
- private _unsortedTags;
- constructor(scene: Scene);
- readonly count: number;
- readonly buffer: Entity[];
- add(entity: Entity): void;
- remove(entity: Entity): void;
- findEntity(name: string): Entity;
- getTagList(tag: number): Entity[];
- addToTagList(entity: Entity): void;
- removeFromTagList(entity: Entity): void;
- update(): void;
- removeAllEntities(): void;
- updateLists(): void;
-}
-declare class EntityProcessorList {
- private _processors;
- add(processor: EntitySystem): void;
- remove(processor: EntitySystem): void;
- onComponentAdded(entity: Entity): void;
- onComponentRemoved(entity: Entity): void;
- onEntityAdded(entity: Entity): void;
- onEntityRemoved(entity: Entity): void;
- protected notifyEntityChanged(entity: Entity): void;
- protected removeFromProcessors(entity: Entity): void;
- begin(): void;
- update(): void;
- lateUpdate(): void;
- end(): void;
- getProcessor(): T;
-}
-declare class Matcher {
- protected allSet: BitSet;
- protected exclusionSet: BitSet;
- protected oneSet: BitSet;
- static empty(): Matcher;
- getAllSet(): BitSet;
- getExclusionSet(): BitSet;
- getOneSet(): BitSet;
- IsIntersted(e: Entity): boolean;
- all(...types: any[]): Matcher;
- exclude(...types: any[]): this;
- one(...types: any[]): this;
-}
-declare class RenderableComponentList {
- private _components;
- readonly count: number;
- readonly buffer: IRenderable[];
- add(component: IRenderable): void;
- remove(component: IRenderable): void;
- updateList(): void;
-}
-declare class Time {
- static unscaledDeltaTime: any;
- static deltaTime: number;
- static timeScale: number;
- static frameCount: number;
- private static _lastTime;
- static update(currentTime: number): void;
-}
-declare class GraphicsCapabilities {
- supportsTextureFilterAnisotropic: boolean;
- supportsNonPowerOfTwo: boolean;
- supportsDepth24: boolean;
- supportsPackedDepthStencil: boolean;
- supportsDepthNonLinear: boolean;
- supportsTextureMaxLevel: boolean;
- supportsS3tc: boolean;
- supportsDxt1: boolean;
- supportsPvrtc: boolean;
- supportsAtitc: boolean;
- supportsFramebufferObjectARB: boolean;
- initialize(device: GraphicsDevice): void;
- private platformInitialize;
-}
-declare class GraphicsDevice {
- private viewport;
- graphicsCapabilities: GraphicsCapabilities;
- constructor();
-}
-declare class Viewport {
- private _x;
- private _y;
- private _width;
- private _height;
- private _minDepth;
- private _maxDepth;
- readonly aspectRatio: number;
- bounds: Rectangle;
- constructor(x: number, y: number, width: number, height: number);
-}
-declare class GaussianBlurEffect extends egret.CustomFilter {
- private static blur_frag;
- constructor();
-}
-declare class PolygonLightEffect extends egret.CustomFilter {
- private static vertSrc;
- private static fragmentSrc;
- constructor();
-}
-declare class PostProcessor {
- enable: boolean;
- effect: egret.Filter;
- scene: Scene;
- shape: egret.Shape;
- static default_vert: string;
- constructor(effect?: egret.Filter);
- onAddedToScene(scene: Scene): void;
- process(): void;
- onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
- protected drawFullscreenQuad(): void;
- unload(): void;
-}
-declare class GaussianBlurPostProcessor extends PostProcessor {
- onAddedToScene(scene: Scene): void;
-}
-declare abstract class Renderer {
- camera: Camera;
- onAddedToScene(scene: Scene): void;
- protected beginRender(cam: Camera): void;
- abstract render(scene: Scene): any;
- unload(): void;
- protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
-}
-declare class DefaultRenderer extends Renderer {
- render(scene: Scene): void;
-}
-interface IRenderable {
- bounds: Rectangle;
- enabled: boolean;
- isVisible: boolean;
- isVisibleFromCamera(camera: Camera): any;
- render(camera: Camera): any;
-}
-declare class ScreenSpaceRenderer extends Renderer {
- render(scene: Scene): void;
-}
-declare class PolyLight extends RenderableComponent {
- power: number;
- protected _radius: number;
- private _lightEffect;
- private _indices;
- radius: number;
- constructor(radius: number, color: number, power: number);
- private computeTriangleIndices;
- setRadius(radius: number): void;
- render(camera: Camera): void;
- reset(): void;
-}
-declare abstract class SceneTransition {
- private _hasPreviousSceneRender;
- loadsNewScene: boolean;
- isNewSceneLoaded: boolean;
- protected sceneLoadAction: Function;
- onScreenObscured: Function;
- onTransitionCompleted: Function;
- readonly hasPreviousSceneRender: boolean;
- constructor(sceneLoadAction: Function);
- preRender(): void;
- render(): void;
- onBeginTransition(): Promise;
- protected transitionComplete(): void;
- protected loadNextScene(): Promise;
- tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<{}>;
-}
-declare class FadeTransition extends SceneTransition {
- fadeToColor: number;
- fadeOutDuration: number;
- fadeEaseType: Function;
- delayBeforeFadeInDuration: number;
- private _mask;
- private _alpha;
- constructor(sceneLoadAction: Function);
- onBeginTransition(): Promise;
- render(): void;
-}
-declare class WindTransition extends SceneTransition {
- private _mask;
- private _windEffect;
- duration: number;
- windSegments: number;
- size: number;
- easeType: (t: number) => number;
- constructor(sceneLoadAction: Function);
- onBeginTransition(): Promise;
-}
-declare class Flags {
- static isFlagSet(self: number, flag: number): boolean;
- static isUnshiftedFlagSet(self: number, flag: number): boolean;
- static setFlagExclusive(self: number, flag: number): number;
- static setFlag(self: number, flag: number): number;
- static unsetFlag(self: number, flag: number): number;
- static invertFlags(self: number): number;
-}
-declare class MathHelper {
- static readonly Epsilon: number;
- static readonly Rad2Deg: number;
- static readonly Deg2Rad: number;
- static toDegrees(radians: number): number;
- static toRadians(degrees: number): number;
- static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number): number;
- static lerp(value1: number, value2: number, amount: number): number;
- static clamp(value: number, min: number, max: number): number;
- static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number): Vector2;
- static isEven(value: number): boolean;
-}
-declare class Matrix2D {
- m11: number;
- m12: number;
- m21: number;
- m22: number;
- m31: number;
- m32: number;
- private static _identity;
- static readonly identity: Matrix2D;
- constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number);
- translation: Vector2;
- rotation: number;
- rotationDegrees: number;
- scale: Vector2;
- static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
- static divide(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
- static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
- static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D;
- determinant(): number;
- static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D;
- static createTranslation(xPosition: number, yPosition: number): Matrix2D;
- static createTranslationVector(position: Vector2): Matrix2D;
- static createRotation(radians: number, result?: Matrix2D): Matrix2D;
- static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D;
- toEgretMatrix(): egret.Matrix;
-}
-declare class Rectangle extends egret.Rectangle {
- readonly max: Vector2;
- readonly center: Vector2;
- location: Vector2;
- size: Vector2;
- intersects(value: egret.Rectangle): boolean;
- containsInVec(value: Vector2): boolean;
- containsRect(value: Rectangle): boolean;
- getHalfSize(): Vector2;
- static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
- getClosestPointOnRectangleBorderToPoint(point: Vector2): {
- res: Vector2;
- edgeNormal: Vector2;
- };
- getClosestPointOnBoundsToOrigin(): Vector2;
- static rectEncompassingPoints(points: Vector2[]): Rectangle;
-}
-declare class Vector3 {
- x: number;
- y: number;
- z: number;
- constructor(x: number, y: number, z: number);
-}
-declare class ColliderTriggerHelper {
- private _entity;
- private _activeTriggerIntersections;
- private _previousTriggerIntersections;
- private _tempTriggerList;
- constructor(entity: Entity);
- update(): void;
- private checkForExitedColliders;
- private notifyTriggerListeners;
-}
-declare enum PointSectors {
- center = 0,
- top = 1,
- bottom = 2,
- topLeft = 9,
- topRight = 5,
- left = 8,
- right = 4,
- bottomLeft = 10,
- bottomRight = 6
-}
-declare class Collisions {
- static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean;
- static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2;
- static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
- static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean;
- static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean;
- static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean;
- static isRectToCircle(rect: Rectangle, cPosition: Vector2, cRadius: number): boolean;
- static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean;
- static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean;
- static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors;
-}
-declare class Physics {
- private static _spatialHash;
- static spatialHashCellSize: number;
- static readonly allLayers: number;
- static reset(): void;
- static clear(): void;
- static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number;
- static boxcastBroadphase(rect: Rectangle, layerMask?: number): {
- colliders: Collider[];
- rect: Rectangle;
- };
- static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): {
- tempHashSet: Collider[];
+ sum(selector: Function): number;
+}
+declare module es {
+ class PriorityQueueNode {
+ priority: number;
+ insertionIndex: number;
+ queueIndex: number;
+ }
+}
+declare module es {
+ class AStarPathfinder {
+ static search(graph: IAstarGraph, start: T, goal: T): T[];
+ static recontructPath(cameFrom: Map, start: T, goal: T): T[];
+ private static hasKey;
+ private static getKey;
+ }
+ class AStarNode extends PriorityQueueNode {
+ data: T;
+ constructor(data: T);
+ }
+}
+declare module es {
+ class AstarGridGraph implements IAstarGraph {
+ dirs: Vector2[];
+ walls: Vector2[];
+ weightedNodes: Vector2[];
+ defaultWeight: number;
+ weightedNodeWeight: number;
+ private _width;
+ private _height;
+ private _neighbors;
+ constructor(width: number, height: number);
+ isNodeInBounds(node: Vector2): boolean;
+ isNodePassable(node: Vector2): boolean;
+ search(start: Vector2, goal: Vector2): Vector2[];
+ getNeighbors(node: Vector2): Vector2[];
+ cost(from: Vector2, to: Vector2): number;
+ heuristic(node: Vector2, goal: Vector2): number;
+ }
+}
+declare module es {
+ interface IAstarGraph {
+ getNeighbors(node: T): Array;
+ cost(from: T, to: T): number;
+ heuristic(node: T, goal: T): any;
+ }
+}
+declare module es {
+ class PriorityQueue {
+ private _numNodes;
+ private _nodes;
+ private _numNodesEverEnqueued;
+ constructor(maxNodes: number);
+ readonly count: number;
+ readonly maxSize: number;
+ clear(): void;
+ contains(node: T): boolean;
+ enqueue(node: T, priority: number): void;
+ dequeue(): T;
+ remove(node: T): void;
+ isValidQueue(): boolean;
+ private onNodeUpdated;
+ private cascadeDown;
+ private cascadeUp;
+ private swap;
+ private hasHigherPriority;
+ }
+}
+declare module es {
+ class BreadthFirstPathfinder {
+ static search(graph: IUnweightedGraph, start: T, goal: T): T[];
+ private static hasKey;
+ }
+}
+declare module es {
+ interface IUnweightedGraph {
+ getNeighbors(node: T): T[];
+ }
+}
+declare module es {
+ class UnweightedGraph implements IUnweightedGraph {
+ edges: Map;
+ addEdgesForNode(node: T, edges: T[]): this;
+ getNeighbors(node: T): T[];
+ }
+}
+declare module es {
+ class Vector2 {
+ private static readonly unitYVector;
+ private static readonly unitXVector;
+ private static readonly unitVector2;
+ private static readonly zeroVector2;
+ x: number;
+ y: number;
+ constructor(x?: number, y?: number);
+ static readonly zero: Vector2;
+ static readonly one: Vector2;
+ static readonly unitX: Vector2;
+ static readonly unitY: Vector2;
+ static add(value1: Vector2, value2: Vector2): Vector2;
+ static divide(value1: Vector2, value2: Vector2): Vector2;
+ static multiply(value1: Vector2, value2: Vector2): Vector2;
+ static subtract(value1: Vector2, value2: Vector2): Vector2;
+ static normalize(value: Vector2): Vector2;
+ static dot(value1: Vector2, value2: Vector2): number;
+ static distanceSquared(value1: Vector2, value2: Vector2): number;
+ static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2;
+ static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
+ static transform(position: Vector2, matrix: Matrix2D): Vector2;
+ static distance(value1: Vector2, value2: Vector2): number;
+ static negate(value: Vector2): Vector2;
+ add(value: Vector2): Vector2;
+ divide(value: Vector2): Vector2;
+ multiply(value: Vector2): Vector2;
+ subtract(value: Vector2): this;
+ normalize(): this;
+ length(): number;
+ lengthSquared(): number;
+ round(): Vector2;
+ equals(other: Vector2): boolean;
+ }
+}
+declare module es {
+ class UnweightedGridGraph implements IUnweightedGraph {
+ private static readonly CARDINAL_DIRS;
+ private static readonly COMPASS_DIRS;
+ walls: Vector2[];
+ private _width;
+ private _hegiht;
+ private _dirs;
+ private _neighbors;
+ constructor(width: number, height: number, allowDiagonalSearch?: boolean);
+ isNodeInBounds(node: Vector2): boolean;
+ isNodePassable(node: Vector2): boolean;
+ getNeighbors(node: Vector2): Vector2[];
+ search(start: Vector2, goal: Vector2): Vector2[];
+ }
+}
+declare module es {
+ interface IWeightedGraph {
+ getNeighbors(node: T): T[];
+ cost(from: T, to: T): number;
+ }
+}
+declare module es {
+ class WeightedGridGraph implements IWeightedGraph {
+ static readonly CARDINAL_DIRS: Vector2[];
+ private static readonly COMPASS_DIRS;
+ walls: Vector2[];
+ weightedNodes: Vector2[];
+ defaultWeight: number;
+ weightedNodeWeight: number;
+ private _width;
+ private _height;
+ private _dirs;
+ private _neighbors;
+ constructor(width: number, height: number, allowDiagonalSearch?: boolean);
+ isNodeInBounds(node: Vector2): boolean;
+ isNodePassable(node: Vector2): boolean;
+ search(start: Vector2, goal: Vector2): Vector2[];
+ getNeighbors(node: Vector2): Vector2[];
+ cost(from: Vector2, to: Vector2): number;
+ }
+}
+declare module es {
+ class WeightedNode extends PriorityQueueNode {
+ data: T;
+ constructor(data: T);
+ }
+ class WeightedPathfinder {
+ static search(graph: IWeightedGraph, start: T, goal: T): T[];
+ static recontructPath(cameFrom: Map, start: T, goal: T): T[];
+ private static hasKey;
+ private static getKey;
+ }
+}
+declare module es {
+ class Debug {
+ private static _debugDrawItems;
+ static drawHollowRect(rectanle: Rectangle, color: number, duration?: number): void;
+ static render(): void;
+ }
+}
+declare module es {
+ class DebugDefaults {
+ static verletParticle: number;
+ static verletConstraintEdge: number;
+ }
+}
+declare module es {
+ enum DebugDrawType {
+ line = 0,
+ hollowRectangle = 1,
+ pixel = 2,
+ text = 3
+ }
+ class DebugDrawItem {
+ rectangle: Rectangle;
+ color: number;
+ duration: number;
+ drawType: DebugDrawType;
+ text: string;
+ start: Vector2;
+ end: Vector2;
+ x: number;
+ y: number;
+ size: number;
+ constructor(rectangle: Rectangle, color: number, duration: number);
+ draw(shape: egret.Shape): boolean;
+ }
+}
+declare module es {
+ abstract class Component extends egret.HashObject {
+ entity: Entity;
+ updateInterval: number;
+ readonly transform: Transform;
+ private _enabled;
+ enabled: boolean;
+ private _updateOrder;
+ updateOrder: number;
+ initialize(): void;
+ onAddedToEntity(): void;
+ onRemovedFromEntity(): void;
+ onEntityTransformChanged(comp: transform.Component): void;
+ debugRender(): void;
+ onEnabled(): void;
+ onDisabled(): void;
+ update(): void;
+ setEnabled(isEnabled: boolean): this;
+ setUpdateOrder(updateOrder: number): this;
+ clone(): Component;
+ }
+}
+declare module es {
+ class Core extends egret.DisplayObjectContainer {
+ static emitter: Emitter;
+ static graphicsDevice: GraphicsDevice;
+ static content: ContentManager;
+ static _instance: Core;
+ _nextScene: Scene;
+ _sceneTransition: SceneTransition;
+ _globalManagers: GlobalManager[];
+ constructor();
+ static readonly Instance: Core;
+ _scene: Scene;
+ static scene: Scene;
+ static startSceneTransition(sceneTransition: T): T;
+ static registerGlobalManager(manager: es.GlobalManager): void;
+ static unregisterGlobalManager(manager: es.GlobalManager): void;
+ static getGlobalManager(type: any): T;
+ onOrientationChanged(): void;
+ draw(): Promise;
+ startDebugUpdate(): void;
+ endDebugUpdate(): void;
+ onSceneChanged(): void;
+ protected onGraphicsDeviceReset(): void;
+ protected initialize(): void;
+ protected update(): Promise;
+ private onAddToStage;
+ }
+}
+declare module es {
+ enum CoreEvents {
+ GraphicsDeviceReset = 0,
+ SceneChanged = 1,
+ OrientationChanged = 2
+ }
+}
+declare module es {
+ class Entity {
+ static _idGenerator: number;
+ scene: Scene;
+ name: string;
+ readonly id: number;
+ readonly transform: Transform;
+ readonly components: ComponentList;
+ updateInterval: number;
+ componentBits: BitSet;
+ constructor(name: string);
+ _isDestroyed: boolean;
+ readonly isDestroyed: boolean;
+ private _tag;
+ tag: number;
+ private _enabled;
+ enabled: boolean;
+ private _updateOrder;
+ updateOrder: number;
+ parent: Transform;
+ readonly childCount: number;
+ position: Vector2;
+ localPosition: Vector2;
+ rotation: number;
+ rotationDegrees: number;
+ localRotation: number;
+ localRotationDegrees: number;
+ scale: Vector2;
+ localScale: Vector2;
+ readonly worldInverseTransform: Matrix2D;
+ readonly localToWorldTransform: Matrix2D;
+ readonly worldToLocalTransform: Matrix2D;
+ onTransformChanged(comp: transform.Component): void;
+ setTag(tag: number): Entity;
+ setEnabled(isEnabled: boolean): this;
+ setUpdateOrder(updateOrder: number): this;
+ destroy(): void;
+ detachFromScene(): void;
+ attachToScene(newScene: Scene): void;
+ clone(position?: Vector2): Entity;
+ onAddedToScene(): void;
+ onRemovedFromScene(): void;
+ update(): void;
+ addComponent(component: T): T;
+ getComponent(type: any): T;
+ hasComponent(type: any): boolean;
+ getOrCreateComponent(type: T): T;
+ getComponents(typeName: string | any, componentList?: any): any;
+ removeComponent(component: Component): void;
+ removeComponentForType(type: any): boolean;
+ removeAllComponents(): void;
+ compareTo(other: Entity): number;
+ toString(): string;
+ protected copyFrom(entity: Entity): void;
+ }
+}
+declare module es {
+ class Scene extends egret.DisplayObjectContainer {
+ camera: Camera;
+ readonly content: ContentManager;
+ enablePostProcessing: boolean;
+ readonly entities: EntityList;
+ readonly renderableComponents: RenderableComponentList;
+ readonly entityProcessors: EntityProcessorList;
+ _renderers: Renderer[];
+ readonly _postProcessors: PostProcessor[];
+ _didSceneBegin: any;
+ constructor();
+ static createWithDefaultRenderer(): Scene;
+ initialize(): void;
+ onStart(): Promise;
+ unload(): void;
+ onActive(): void;
+ onDeactive(): void;
+ begin(): Promise;
+ end(): void;
+ update(): void;
+ render(): void;
+ postRender(): void;
+ addRenderer(renderer: T): T;
+ getRenderer(type: any): T;
+ removeRenderer(renderer: Renderer): void;
+ addPostProcessor(postProcessor: T): T;
+ getPostProcessor(type: any): T;
+ removePostProcessor(postProcessor: PostProcessor): void;
+ createEntity(name: string): Entity;
+ addEntity(entity: Entity): Entity;
+ destroyAllEntities(): void;
+ findEntity(name: string): Entity;
+ findEntitiesWithTag(tag: number): Entity[];
+ entitiesOfType(type: any): T[];
+ findComponentOfType(type: any): T;
+ findComponentsOfType(type: any): T[];
+ addEntityProcessor(processor: EntitySystem): EntitySystem;
+ removeEntityProcessor(processor: EntitySystem): void;
+ getEntityProcessor(): T;
+ }
+}
+declare module transform {
+ enum Component {
+ position = 0,
+ scale = 1,
+ rotation = 2
+ }
+}
+declare module es {
+ import HashObject = egret.HashObject;
+ enum DirtyType {
+ clean = 0,
+ positionDirty = 1,
+ scaleDirty = 2,
+ rotationDirty = 3
+ }
+ class Transform extends HashObject {
+ readonly entity: Entity;
+ hierarchyDirty: DirtyType;
+ _localDirty: boolean;
+ _localPositionDirty: boolean;
+ _localScaleDirty: boolean;
+ _localRotationDirty: boolean;
+ _positionDirty: boolean;
+ _worldToLocalDirty: boolean;
+ _worldInverseDirty: boolean;
+ _localTransform: Matrix2D;
+ _worldTransform: Matrix2D;
+ _rotationMatrix: Matrix2D;
+ _translationMatrix: Matrix2D;
+ _scaleMatrix: Matrix2D;
+ _children: Transform[];
+ constructor(entity: Entity);
+ readonly childCount: number;
+ rotationDegrees: number;
+ localRotationDegrees: number;
+ readonly localToWorldTransform: Matrix2D;
+ _parent: Transform;
+ parent: Transform;
+ _worldToLocalTransform: Matrix2D;
+ readonly worldToLocalTransform: Matrix2D;
+ _worldInverseTransform: Matrix2D;
+ readonly worldInverseTransform: Matrix2D;
+ _position: Vector2;
+ position: Vector2;
+ _scale: Vector2;
+ scale: Vector2;
+ _rotation: number;
+ rotation: number;
+ _localPosition: Vector2;
+ localPosition: Vector2;
+ _localScale: Vector2;
+ localScale: Vector2;
+ _localRotation: number;
+ localRotation: number;
+ getChild(index: number): Transform;
+ setParent(parent: Transform): Transform;
+ setPosition(x: number, y: number): Transform;
+ setLocalPosition(localPosition: Vector2): Transform;
+ setRotation(radians: number): Transform;
+ setRotationDegrees(degrees: number): Transform;
+ lookAt(pos: Vector2): void;
+ setLocalRotation(radians: number): this;
+ setLocalRotationDegrees(degrees: number): Transform;
+ setScale(scale: Vector2): Transform;
+ setLocalScale(scale: Vector2): Transform;
+ roundPosition(): void;
+ updateTransform(): void;
+ setDirty(dirtyFlagType: DirtyType): void;
+ copyFrom(transform: Transform): void;
+ toString(): string;
+ equals(other: Transform): boolean;
+ }
+}
+declare module es {
+ enum CameraStyle {
+ lockOn = 0,
+ cameraWindow = 1
+ }
+ class CameraInset {
+ left: number;
+ right: number;
+ top: number;
+ bottom: number;
+ }
+ class Camera extends Component {
+ _inset: CameraInset;
+ _areMatrixedDirty: boolean;
+ _areBoundsDirty: boolean;
+ _isProjectionMatrixDirty: boolean;
+ followLerp: number;
+ deadzone: Rectangle;
+ focusOffset: Vector2;
+ mapLockEnabled: boolean;
+ mapSize: Vector2;
+ _targetEntity: Entity;
+ _targetCollider: Collider;
+ _desiredPositionDelta: Vector2;
+ _cameraStyle: CameraStyle;
+ _worldSpaceDeadZone: Rectangle;
+ constructor(targetEntity?: Entity, cameraStyle?: CameraStyle);
+ position: Vector2;
+ rotation: number;
+ _zoom: any;
+ zoom: number;
+ _minimumZoom: number;
+ minimumZoom: number;
+ _maximumZoom: number;
+ maximumZoom: number;
+ _bounds: Rectangle;
+ readonly bounds: Rectangle;
+ _transformMatrix: Matrix2D;
+ readonly transformMatrix: Matrix2D;
+ _inverseTransformMatrix: Matrix2D;
+ readonly inverseTransformMatrix: Matrix2D;
+ _origin: Vector2;
+ origin: Vector2;
+ onSceneSizeChanged(newWidth: number, newHeight: number): void;
+ setInset(left: number, right: number, top: number, bottom: number): Camera;
+ setPosition(position: Vector2): this;
+ setRotation(rotation: number): Camera;
+ setZoom(zoom: number): Camera;
+ setMinimumZoom(minZoom: number): Camera;
+ setMaximumZoom(maxZoom: number): Camera;
+ onEntityTransformChanged(comp: transform.Component): void;
+ zoomIn(deltaZoom: number): void;
+ zoomOut(deltaZoom: number): void;
+ worldToScreenPoint(worldPosition: Vector2): Vector2;
+ screenToWorldPoint(screenPosition: Vector2): Vector2;
+ mouseToWorldPoint(): Vector2;
+ onAddedToEntity(): void;
+ update(): void;
+ clampToMapSize(position: Vector2): Vector2;
+ updateFollow(): void;
+ follow(targetEntity: Entity, cameraStyle?: CameraStyle): void;
+ setCenteredDeadzone(width: number, height: number): void;
+ protected updateMatrixes(): void;
+ }
+}
+declare module es {
+ class ComponentPool {
+ private _cache;
+ private _type;
+ constructor(typeClass: any);
+ obtain(): T;
+ free(component: T): void;
+ }
+}
+declare module es {
+ class IUpdatableComparer {
+ compare(a: Component, b: Component): number;
+ }
+}
+declare module es {
+ abstract class PooledComponent extends Component {
+ abstract reset(): any;
+ }
+}
+declare module es {
+ abstract class RenderableComponent extends Component implements IRenderable {
+ displayObject: egret.DisplayObject;
+ color: number;
+ protected _areBoundsDirty: boolean;
+ readonly width: number;
+ readonly height: number;
+ protected _localOffset: Vector2;
+ localOffset: Vector2;
+ protected _renderLayer: number;
+ renderLayer: number;
+ protected _bounds: Rectangle;
+ readonly bounds: Rectangle;
+ private _isVisible;
+ isVisible: boolean;
+ onEntityTransformChanged(comp: transform.Component): void;
+ abstract render(camera: Camera): any;
+ isVisibleFromCamera(camera: Camera): boolean;
+ setRenderLayer(renderLayer: number): RenderableComponent;
+ setColor(color: number): RenderableComponent;
+ setLocalOffset(offset: Vector2): RenderableComponent;
+ sync(camera: Camera): void;
+ toString(): string;
+ protected onBecameVisible(): void;
+ protected onBecameInvisible(): void;
+ }
+}
+declare module es {
+ class Mesh extends RenderableComponent {
+ private _mesh;
+ constructor();
+ setTexture(texture: egret.Texture): Mesh;
+ reset(): void;
+ render(camera: es.Camera): void;
+ }
+}
+declare module es {
+ class SpriteRenderer extends RenderableComponent {
+ constructor(sprite?: Sprite | egret.Texture);
+ readonly bounds: Rectangle;
+ originNormalized: Vector2;
+ protected _origin: Vector2;
+ origin: Vector2;
+ protected _sprite: Sprite;
+ sprite: Sprite;
+ setSprite(sprite: Sprite): SpriteRenderer;
+ setOrigin(origin: Vector2): SpriteRenderer;
+ setOriginNormalized(value: Vector2): SpriteRenderer;
+ render(camera: Camera): void;
+ }
+}
+declare module es {
+ class TiledSpriteRenderer extends SpriteRenderer {
+ readonly bounds: Rectangle;
+ scrollX: number;
+ scrollY: number;
+ textureScale: Vector2;
+ width: number;
+ height: number;
+ protected _sourceRect: Rectangle;
+ protected _textureScale: Vector2;
+ protected _inverseTexScale: Vector2;
+ constructor(sprite: Sprite);
+ render(camera: es.Camera): void;
+ }
+}
+declare module es {
+ class ScrollingSpriteRenderer extends TiledSpriteRenderer {
+ scrollSpeedX: number;
+ scroolSpeedY: number;
+ textureScale: Vector2;
+ private _scrollX;
+ private _scrollY;
+ constructor(sprite: Sprite);
+ update(): void;
+ }
+}
+declare module es {
+ class Sprite {
+ texture2D: egret.Texture;
+ readonly sourceRect: Rectangle;
+ readonly center: Vector2;
+ origin: Vector2;
+ readonly uvs: Rectangle;
+ constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2);
+ }
+}
+declare module es {
+ class SpriteAnimation {
+ readonly sprites: Sprite[];
+ readonly frameRate: number;
+ constructor(sprites: Sprite[], frameRate: number);
+ }
+}
+declare module es {
+ enum LoopMode {
+ loop = 0,
+ once = 1,
+ clampForever = 2,
+ pingPong = 3,
+ pingPongOnce = 4
+ }
+ enum State {
+ none = 0,
+ running = 1,
+ paused = 2,
+ completed = 3
+ }
+ class SpriteAnimator extends SpriteRenderer {
+ onAnimationCompletedEvent: (string: any) => {};
+ speed: number;
+ animationState: State;
+ currentAnimation: SpriteAnimation;
+ currentAnimationName: string;
+ currentFrame: number;
+ _elapsedTime: number;
+ _loopMode: LoopMode;
+ constructor(sprite?: Sprite);
+ readonly isRunning: boolean;
+ private _animations;
+ readonly animations: Map;
+ update(): void;
+ addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator;
+ play(name: string, loopMode?: LoopMode): void;
+ isAnimationActive(name: string): boolean;
+ pause(): void;
+ unPause(): void;
+ stop(): void;
+ }
+}
+declare module es {
+ interface ITriggerListener {
+ onTriggerEnter(other: Collider, local: Collider): any;
+ onTriggerExit(other: Collider, local: Collider): any;
+ }
+}
+declare module es {
+ class Mover extends Component {
+ private _triggerHelper;
+ onAddedToEntity(): void;
+ calculateMovement(motion: Vector2, collisionResult: CollisionResult): boolean;
+ applyMovement(motion: Vector2): void;
+ move(motion: Vector2, collisionResult: CollisionResult): boolean;
+ }
+}
+declare module es {
+ class ProjectileMover extends Component {
+ private _tempTriggerList;
+ private _collider;
+ onAddedToEntity(): void;
+ move(motion: Vector2): boolean;
+ private notifyTriggerListeners;
+ }
+}
+declare module es {
+ abstract class Collider extends Component {
+ shape: Shape;
+ isTrigger: boolean;
+ physicsLayer: number;
+ collidesWithLayers: number;
+ shouldColliderScaleAndRotateWithTransform: boolean;
+ registeredPhysicsBounds: Rectangle;
+ _localOffsetLength: number;
+ _isPositionDirty: boolean;
+ _isRotationDirty: boolean;
+ protected _colliderRequiresAutoSizing: any;
+ protected _isParentEntityAddedToScene: any;
+ protected _isColliderRegistered: any;
+ readonly absolutePosition: Vector2;
+ readonly rotation: number;
+ readonly bounds: Rectangle;
+ protected _localOffset: Vector2;
+ localOffset: Vector2;
+ setLocalOffset(offset: Vector2): Collider;
+ setShouldColliderScaleAndRotateWithTransform(shouldColliderScaleAndRotationWithTransform: boolean): Collider;
+ onAddedToEntity(): void;
+ onRemovedFromEntity(): void;
+ onEntityTransformChanged(comp: transform.Component): void;
+ onEnabled(): void;
+ onDisabled(): void;
+ registerColliderWithPhysicsSystem(): void;
+ unregisterColliderWithPhysicsSystem(): void;
+ overlaps(other: Collider): boolean;
+ collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean;
+ clone(): Component;
+ }
+}
+declare module es {
+ class BoxCollider extends Collider {
+ constructor();
+ width: number;
+ height: number;
+ setSize(width: number, height: number): this;
+ setWidth(width: number): BoxCollider;
+ setHeight(height: number): void;
+ toString(): string;
+ }
+}
+declare module es {
+ class CircleCollider extends Collider {
+ constructor(radius?: number);
+ radius: number;
+ setRadius(radius: number): CircleCollider;
+ toString(): string;
+ }
+}
+declare module es {
+ class PolygonCollider extends Collider {
+ constructor(points: Vector2[]);
+ }
+}
+declare module es {
+ class EntitySystem {
+ private _entities;
+ constructor(matcher?: Matcher);
+ private _scene;
+ scene: Scene;
+ private _matcher;
+ readonly matcher: Matcher;
+ initialize(): void;
+ onChanged(entity: Entity): void;
+ add(entity: Entity): void;
+ onAdded(entity: Entity): void;
+ remove(entity: Entity): void;
+ onRemoved(entity: Entity): void;
+ update(): void;
+ lateUpdate(): void;
+ protected begin(): void;
+ protected process(entities: Entity[]): void;
+ protected lateProcess(entities: Entity[]): void;
+ protected end(): void;
+ }
+}
+declare module es {
+ abstract class EntityProcessingSystem extends EntitySystem {
+ constructor(matcher: Matcher);
+ abstract processEntity(entity: Entity): any;
+ lateProcessEntity(entity: Entity): void;
+ protected process(entities: Entity[]): void;
+ protected lateProcess(entities: Entity[]): void;
+ }
+}
+declare module es {
+ abstract class PassiveSystem extends EntitySystem {
+ onChanged(entity: Entity): void;
+ protected process(entities: Entity[]): void;
+ }
+}
+declare module es {
+ abstract class ProcessingSystem extends EntitySystem {
+ onChanged(entity: Entity): void;
+ abstract processSystem(): any;
+ protected process(entities: Entity[]): void;
+ }
+}
+declare module es {
+ class BitSet {
+ private static LONG_MASK;
+ private _bits;
+ constructor(nbits?: number);
+ and(bs: BitSet): void;
+ andNot(bs: BitSet): void;
+ cardinality(): number;
+ clear(pos?: number): void;
+ get(pos: number): boolean;
+ intersects(set: BitSet): boolean;
+ isEmpty(): boolean;
+ nextSetBit(from: number): number;
+ set(pos: number, value?: boolean): void;
+ private ensure;
+ }
+}
+declare module es {
+ class ComponentList {
+ static compareUpdatableOrder: IUpdatableComparer;
+ _entity: Entity;
+ _components: Component[];
+ _componentsToAdd: Component[];
+ _componentsToRemove: Component[];
+ _tempBufferList: Component[];
+ _isComponentListUnsorted: boolean;
+ constructor(entity: Entity);
+ readonly count: number;
+ readonly buffer: Component[];
+ markEntityListUnsorted(): void;
+ add(component: Component): void;
+ remove(component: Component): void;
+ removeAllComponents(): void;
+ deregisterAllComponents(): void;
+ registerAllComponents(): void;
+ updateLists(): void;
+ handleRemove(component: Component): void;
+ getComponent(type: any, onlyReturnInitializedComponents: boolean): T;
+ getComponents(typeName: string | any, components?: any): any;
+ update(): void;
+ onEntityTransformChanged(comp: transform.Component): void;
+ onEntityEnabled(): void;
+ onEntityDisabled(): void;
+ }
+}
+declare module es {
+ class ComponentTypeManager {
+ private static _componentTypesMask;
+ static add(type: any): void;
+ static getIndexFor(type: any): number;
+ }
+}
+declare module es {
+ class EntityList {
+ scene: Scene;
+ _entities: Entity[];
+ _entitiesToAdded: Entity[];
+ _entitiesToRemove: Entity[];
+ _isEntityListUnsorted: boolean;
+ _entityDict: Map;
+ _unsortedTags: number[];
+ _tempEntityList: Entity[];
+ constructor(scene: Scene);
+ readonly count: number;
+ readonly buffer: Entity[];
+ markEntityListUnsorted(): void;
+ markTagUnsorted(tag: number): void;
+ add(entity: Entity): void;
+ remove(entity: Entity): void;
+ removeAllEntities(): void;
+ contains(entity: Entity): boolean;
+ getTagList(tag: number): Entity[];
+ addToTagList(entity: Entity): void;
+ removeFromTagList(entity: Entity): void;
+ update(): void;
+ updateLists(): void;
+ findEntity(name: string): Entity;
+ entitiesWithTag(tag: number): Entity[];
+ entitiesOfType(type: any): T[];
+ findComponentOfType(type: any): T;
+ findComponentsOfType(type: any): T[];
+ }
+}
+declare module es {
+ class EntityProcessorList {
+ private _processors;
+ add(processor: EntitySystem): void;
+ remove(processor: EntitySystem): void;
+ onComponentAdded(entity: Entity): void;
+ onComponentRemoved(entity: Entity): void;
+ onEntityAdded(entity: Entity): void;
+ onEntityRemoved(entity: Entity): void;
+ begin(): void;
+ update(): void;
+ lateUpdate(): void;
+ end(): void;
+ getProcessor(): T;
+ protected notifyEntityChanged(entity: Entity): void;
+ protected removeFromProcessors(entity: Entity): void;
+ }
+}
+declare module es {
+ class Matcher {
+ protected allSet: BitSet;
+ protected exclusionSet: BitSet;
+ protected oneSet: BitSet;
+ static empty(): Matcher;
+ getAllSet(): BitSet;
+ getExclusionSet(): BitSet;
+ getOneSet(): BitSet;
+ IsIntersted(e: Entity): boolean;
+ all(...types: any[]): Matcher;
+ exclude(...types: any[]): this;
+ one(...types: any[]): this;
+ }
+}
+declare class ObjectUtils {
+ static clone(p: any, c?: T): T;
+}
+declare module es {
+ interface IRenderable {
bounds: Rectangle;
- };
- static addCollider(collider: Collider): void;
- static removeCollider(collider: Collider): void;
- static updateCollider(collider: Collider): void;
+ enabled: boolean;
+ renderLayer: number;
+ isVisible: boolean;
+ isVisibleFromCamera(camera: Camera): any;
+ render(camera: Camera): any;
+ }
+ class RenderableComparer {
+ compare(self: IRenderable, other: IRenderable): number;
+ }
}
-declare abstract class Shape {
- bounds: Rectangle;
- position: Vector2;
- center: Vector2;
- abstract recalculateBounds(collider: Collider): any;
- abstract pointCollidesWithShape(point: Vector2): CollisionResult;
- abstract overlaps(other: Shape): any;
- abstract collidesWithShape(other: Shape): CollisionResult;
+declare module es {
+ class RenderableComponentList {
+ static compareUpdatableOrder: RenderableComparer;
+ _components: IRenderable[];
+ _componentsByRenderLayer: Map;
+ _unsortedRenderLayers: number[];
+ _componentsNeedSort: boolean;
+ readonly count: number;
+ readonly buffer: IRenderable[];
+ add(component: IRenderable): void;
+ remove(component: IRenderable): void;
+ updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number): void;
+ setRenderLayerNeedsComponentSort(renderLayer: number): void;
+ setNeedsComponentSort(): void;
+ addToRenderLayerList(component: IRenderable, renderLayer: number): void;
+ componentsWithRenderLayer(renderLayer: number): IRenderable[];
+ updateList(): void;
+ }
}
-declare class Polygon extends Shape {
- points: Vector2[];
- isUnrotated: boolean;
- private _polygonCenter;
- private _areEdgeNormalsDirty;
- protected _originalPoints: Vector2[];
- _edgeNormals: Vector2[];
- readonly edgeNormals: Vector2[];
- isBox: boolean;
- constructor(points: Vector2[], isBox?: boolean);
- private buildEdgeNormals;
- setPoints(points: Vector2[]): void;
- collidesWithShape(other: Shape): any;
- recalculateCenterAndEdgeNormals(): void;
- overlaps(other: Shape): any;
- static findPolygonCenter(points: Vector2[]): Vector2;
- static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): {
- closestPoint: any;
- distanceSquared: any;
- edgeNormal: any;
- };
- pointCollidesWithShape(point: Vector2): CollisionResult;
- containsPoint(point: Vector2): boolean;
- static buildSymmertricalPolygon(vertCount: number, radius: number): any[];
- recalculateBounds(collider: Collider): void;
+declare class StringUtils {
+ private static specialSigns;
+ static matchChineseWord(str: string): string[];
+ static lTrim(target: string): string;
+ static rTrim(target: string): string;
+ static trim(target: string): string;
+ static isWhiteSpace(str: string): boolean;
+ static replaceMatch(mainStr: string, targetStr: string, replaceStr: string, caseMark?: boolean): string;
+ static htmlSpecialChars(str: string, reversion?: boolean): string;
+ static zfill(str: string, width?: number): string;
+ static reverse(str: string): string;
+ static cutOff(str: string, start: number, len: number, order?: boolean): string;
+ static strReplace(str: string, rStr: string[]): string;
}
-declare class Box extends Polygon {
- width: number;
- height: number;
- constructor(width: number, height: number);
- private static buildBox;
- overlaps(other: Shape): any;
- collidesWithShape(other: Shape): any;
- updateBox(width: number, height: number): void;
- containsPoint(point: Vector2): boolean;
+declare module es {
+ class TextureUtils {
+ static sharedCanvas: HTMLCanvasElement;
+ static sharedContext: CanvasRenderingContext2D;
+ static convertImageToCanvas(texture: egret.Texture, rect?: egret.Rectangle): HTMLCanvasElement;
+ static toDataURL(type: string, texture: egret.Texture, rect?: egret.Rectangle, encoderOptions?: any): string;
+ static eliFoTevas(type: string, texture: egret.Texture, filePath: string, rect?: egret.Rectangle, encoderOptions?: any): void;
+ static getPixel32(texture: egret.Texture, x: number, y: number): number[];
+ static getPixels(texture: egret.Texture, x: number, y: number, width?: number, height?: number): number[];
+ }
}
-declare class Circle extends Shape {
- radius: number;
- private _originalRadius;
- constructor(radius: number);
- pointCollidesWithShape(point: Vector2): CollisionResult;
- collidesWithShape(other: Shape): CollisionResult;
- recalculateBounds(collider: Collider): void;
- overlaps(other: Shape): any;
+declare module es {
+ class Time {
+ static unscaledDeltaTime: any;
+ static deltaTime: number;
+ static timeScale: number;
+ static frameCount: number;
+ static _timeSinceSceneLoad: any;
+ private static _lastTime;
+ static update(currentTime: number): void;
+ static sceneChanged(): void;
+ static checkEvery(interval: number): boolean;
+ }
}
-declare class CollisionResult {
- collider: Collider;
- minimumTranslationVector: Vector2;
- normal: Vector2;
- point: Vector2;
- invertResult(): void;
+declare class TimeUtils {
+ static monthId(d?: Date): number;
+ static dateId(t?: Date): number;
+ static weekId(d?: Date, first?: boolean): number;
+ static diffDay(a: Date, b: Date, fixOne?: boolean): number;
+ static getFirstDayOfWeek(d?: Date): Date;
+ static getFirstOfDay(d?: Date): Date;
+ static getNextFirstOfDay(d?: Date): Date;
+ static formatDate(date: Date): string;
+ static formatDateTime(date: Date): string;
+ static parseDate(s: string): Date;
+ static secondToTime(time?: number, partition?: string, showHour?: boolean): string;
+ static timeToMillisecond(time: string, partition?: string): string;
}
-declare class ShapeCollisions {
- static polygonToPolygon(first: Polygon, second: Polygon): CollisionResult;
- static intervalDistance(minA: number, maxA: number, minB: number, maxB: any): number;
- static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number): {
+declare module es {
+ class GraphicsCapabilities extends egret.Capabilities {
+ initialize(device: GraphicsDevice): void;
+ private platformInitialize;
+ }
+}
+declare module es {
+ class GraphicsDevice {
+ graphicsCapabilities: GraphicsCapabilities;
+ constructor();
+ private _viewport;
+ readonly viewport: Viewport;
+ private setup;
+ }
+}
+declare module es {
+ class Viewport {
+ private _x;
+ private _y;
+ private _minDepth;
+ private _maxDepth;
+ constructor(x: number, y: number, width: number, height: number);
+ private _width;
+ width: number;
+ private _height;
+ height: number;
+ readonly aspectRatio: number;
+ bounds: Rectangle;
+ }
+}
+declare module es {
+ class GaussianBlurEffect extends egret.CustomFilter {
+ private static blur_frag;
+ constructor();
+ }
+}
+declare module es {
+ class PolygonLightEffect extends egret.CustomFilter {
+ private static vertSrc;
+ private static fragmentSrc;
+ constructor();
+ }
+}
+declare module es {
+ class PostProcessor {
+ static default_vert: string;
+ enabled: boolean;
+ effect: egret.Filter;
+ scene: Scene;
+ shape: egret.Shape;
+ constructor(effect?: egret.Filter);
+ onAddedToScene(scene: Scene): void;
+ process(): void;
+ onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
+ unload(): void;
+ protected drawFullscreenQuad(): void;
+ }
+}
+declare module es {
+ class GaussianBlurPostProcessor extends PostProcessor {
+ onAddedToScene(scene: Scene): void;
+ }
+}
+declare module es {
+ abstract class Renderer {
+ camera: Camera;
+ readonly renderOrder: number;
+ protected constructor(renderOrder: number, camera?: Camera);
+ onAddedToScene(scene: Scene): void;
+ unload(): void;
+ abstract render(scene: Scene): any;
+ onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
+ compareTo(other: Renderer): number;
+ protected beginRender(cam: Camera): void;
+ protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
+ }
+}
+declare module es {
+ class DefaultRenderer extends Renderer {
+ constructor();
+ render(scene: Scene): void;
+ }
+}
+declare module es {
+ class ScreenSpaceRenderer extends Renderer {
+ render(scene: Scene): void;
+ }
+}
+declare module es {
+ class PolyLight extends RenderableComponent {
+ power: number;
+ private _lightEffect;
+ private _indices;
+ constructor(radius: number, color: number, power: number);
+ protected _radius: number;
+ radius: number;
+ setRadius(radius: number): void;
+ render(camera: Camera): void;
+ reset(): void;
+ private computeTriangleIndices;
+ }
+}
+declare module es {
+ abstract class SceneTransition {
+ loadsNewScene: boolean;
+ isNewSceneLoaded: boolean;
+ onScreenObscured: Function;
+ onTransitionCompleted: Function;
+ protected sceneLoadAction: Function;
+ constructor(sceneLoadAction: Function);
+ private _hasPreviousSceneRender;
+ readonly hasPreviousSceneRender: boolean;
+ preRender(): void;
+ render(): void;
+ onBeginTransition(): Promise;
+ tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise;
+ protected transitionComplete(): void;
+ protected loadNextScene(): Promise;
+ }
+}
+declare module es {
+ class FadeTransition extends SceneTransition {
+ fadeToColor: number;
+ fadeOutDuration: number;
+ fadeEaseType: Function;
+ delayBeforeFadeInDuration: number;
+ private _mask;
+ private _alpha;
+ constructor(sceneLoadAction: Function);
+ onBeginTransition(): Promise;
+ render(): void;
+ }
+}
+declare module es {
+ class WindTransition extends SceneTransition {
+ duration: number;
+ easeType: (t: number) => number;
+ private _mask;
+ private _windEffect;
+ constructor(sceneLoadAction: Function);
+ windSegments: number;
+ size: number;
+ onBeginTransition(): Promise;
+ }
+}
+declare module es {
+ class Bezier {
+ static getPoint(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2;
+ static getFirstDerivative(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2;
+ static getFirstDerivativeThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2;
+ static getPointThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2;
+ static getOptimizedDrawingPoints(start: Vector2, firstCtrlPoint: Vector2, secondCtrlPoint: Vector2, end: Vector2, distanceTolerance?: number): Vector2[];
+ private static recursiveGetOptimizedDrawingPoints;
+ }
+}
+declare module es {
+ class Flags {
+ static isFlagSet(self: number, flag: number): boolean;
+ static isUnshiftedFlagSet(self: number, flag: number): boolean;
+ static setFlagExclusive(self: number, flag: number): number;
+ static setFlag(self: number, flag: number): number;
+ static unsetFlag(self: number, flag: number): number;
+ static invertFlags(self: number): number;
+ }
+}
+declare module es {
+ class MathHelper {
+ static readonly Epsilon: number;
+ static readonly Rad2Deg: number;
+ static readonly Deg2Rad: number;
+ static toDegrees(radians: number): number;
+ static toRadians(degrees: number): number;
+ static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number): number;
+ static lerp(value1: number, value2: number, amount: number): number;
+ static clamp(value: number, min: number, max: number): number;
+ static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number): Vector2;
+ static isEven(value: number): boolean;
+ static clamp01(value: number): number;
+ static angleBetweenVectors(from: Vector2, to: Vector2): number;
+ }
+}
+declare module es {
+ var matrixPool: any[];
+ class Matrix2D extends egret.Matrix {
+ m11: number;
+ m12: number;
+ m21: number;
+ m22: number;
+ m31: number;
+ m32: number;
+ static create(): Matrix2D;
+ identity(): Matrix2D;
+ translate(dx: number, dy: number): Matrix2D;
+ scale(sx: number, sy: number): Matrix2D;
+ rotate(angle: number): Matrix2D;
+ invert(): Matrix2D;
+ add(matrix: Matrix2D): Matrix2D;
+ substract(matrix: Matrix2D): Matrix2D;
+ divide(matrix: Matrix2D): Matrix2D;
+ multiply(matrix: Matrix2D): Matrix2D;
+ determinant(): number;
+ release(matrix: Matrix2D): void;
+ }
+}
+declare module es {
+ class Rectangle extends egret.Rectangle {
+ _tempMat: Matrix2D;
+ _transformMat: Matrix2D;
+ readonly max: Vector2;
+ readonly center: Vector2;
+ location: Vector2;
+ size: Vector2;
+ static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
+ static rectEncompassingPoints(points: Vector2[]): Rectangle;
+ intersects(value: egret.Rectangle): boolean;
+ rayIntersects(ray: Ray2D): number;
+ containsRect(value: Rectangle): boolean;
+ contains(x: number, y: number): boolean;
+ getHalfSize(): Vector2;
+ getClosestPointOnRectangleBorderToPoint(point: Vector2, edgeNormal: Vector2): Vector2;
+ getClosestPointOnBoundsToOrigin(): Vector2;
+ calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
+ }
+}
+declare module es {
+ class Vector3 {
+ x: number;
+ y: number;
+ z: number;
+ constructor(x: number, y: number, z: number);
+ }
+}
+declare module es {
+ class ColliderTriggerHelper {
+ private _entity;
+ private _activeTriggerIntersections;
+ private _previousTriggerIntersections;
+ private _tempTriggerList;
+ constructor(entity: Entity);
+ update(): void;
+ private checkForExitedColliders;
+ private notifyTriggerListeners;
+ }
+}
+declare module es {
+ enum PointSectors {
+ center = 0,
+ top = 1,
+ bottom = 2,
+ topLeft = 9,
+ topRight = 5,
+ left = 8,
+ right = 4,
+ bottomLeft = 10,
+ bottomRight = 6
+ }
+ class Collisions {
+ static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean;
+ static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2;
+ static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
+ static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean;
+ static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean;
+ static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean;
+ static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean;
+ static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean;
+ static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean;
+ static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors;
+ }
+}
+declare module es {
+ class Physics {
+ static spatialHashCellSize: number;
+ static readonly allLayers: number;
+ private static _spatialHash;
+ static raycastsHitTriggers: boolean;
+ static raycastsStartInColliders: boolean;
+ static reset(): void;
+ static clear(): void;
+ static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number;
+ static boxcastBroadphase(rect: Rectangle, layerMask?: number): Collider[];
+ static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): Collider[];
+ static addCollider(collider: Collider): void;
+ static removeCollider(collider: Collider): void;
+ static updateCollider(collider: Collider): void;
+ static debugDraw(secondsToDisplay: any): void;
+ }
+}
+declare module es {
+ class Ray2D {
+ start: Vector2;
+ end: Vector2;
+ direction: Vector2;
+ constructor(position: Vector2, end: Vector2);
+ }
+}
+declare module es {
+ class RaycastHit {
+ collider: Collider;
+ fraction: number;
+ distance: number;
+ point: Vector2;
+ normal: Vector2;
+ centroid: Vector2;
+ constructor(collider: Collider, fraction: number, distance: number, point: Vector2, normal: Vector2);
+ setValues(collider: Collider, fraction: number, distance: number, point: Vector2): void;
+ setValuesNonCollider(fraction: number, distance: number, point: Vector2, normal: Vector2): void;
+ reset(): void;
+ toString(): string;
+ }
+}
+declare module es {
+ abstract class Shape {
+ position: Vector2;
+ center: Vector2;
+ bounds: Rectangle;
+ abstract recalculateBounds(collider: Collider): any;
+ abstract overlaps(other: Shape): boolean;
+ abstract collidesWithShape(other: Shape, collisionResult: CollisionResult): boolean;
+ abstract collidesWithLine(start: Vector2, end: Vector2, hit: RaycastHit): boolean;
+ abstract containsPoint(point: Vector2): any;
+ abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
+ clone(): Shape;
+ }
+}
+declare module es {
+ class Polygon extends Shape {
+ points: Vector2[];
+ _areEdgeNormalsDirty: boolean;
+ _originalPoints: Vector2[];
+ _polygonCenter: Vector2;
+ isBox: boolean;
+ isUnrotated: boolean;
+ constructor(points: Vector2[], isBox?: boolean);
+ _edgeNormals: Vector2[];
+ readonly edgeNormals: Vector2[];
+ setPoints(points: Vector2[]): void;
+ recalculateCenterAndEdgeNormals(): void;
+ buildEdgeNormals(): void;
+ static buildSymmetricalPolygon(vertCount: number, radius: number): any[];
+ static recenterPolygonVerts(points: Vector2[]): void;
+ static findPolygonCenter(points: Vector2[]): Vector2;
+ static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2;
+ static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: number, edgeNormal: Vector2): Vector2;
+ static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: any): void;
+ recalculateBounds(collider: Collider): void;
+ overlaps(other: Shape): any;
+ collidesWithShape(other: Shape, result: CollisionResult): boolean;
+ collidesWithLine(start: es.Vector2, end: es.Vector2, hit: es.RaycastHit): boolean;
+ containsPoint(point: Vector2): boolean;
+ pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
+ }
+}
+declare module es {
+ class Box extends Polygon {
+ width: number;
+ height: number;
+ constructor(width: number, height: number);
+ private static buildBox;
+ updateBox(width: number, height: number): void;
+ overlaps(other: Shape): any;
+ collidesWithShape(other: Shape, result: CollisionResult): boolean;
+ containsPoint(point: Vector2): boolean;
+ pointCollidesWithShape(point: es.Vector2, result: es.CollisionResult): boolean;
+ }
+}
+declare module es {
+ class Circle extends Shape {
+ radius: number;
+ _originalRadius: number;
+ constructor(radius: number);
+ recalculateBounds(collider: es.Collider): void;
+ overlaps(other: Shape): any;
+ collidesWithShape(other: Shape, result: CollisionResult): boolean;
+ collidesWithLine(start: es.Vector2, end: es.Vector2, hit: es.RaycastHit): boolean;
+ containsPoint(point: es.Vector2): boolean;
+ pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
+ }
+}
+declare module es {
+ class CollisionResult {
+ collider: Collider;
+ normal: Vector2;
+ minimumTranslationVector: Vector2;
+ point: Vector2;
+ removeHorizontal(deltaMovement: Vector2): void;
+ invertResult(): this;
+ toString(): string;
+ }
+}
+declare module es {
+ class RealtimeCollisions {
+ static intersectMovingCircleToBox(s: Circle, b: Box, movement: Vector2): number;
+ }
+}
+declare module es {
+ class ShapeCollisions {
+ static polygonToPolygon(first: Polygon, second: Polygon, result: CollisionResult): boolean;
+ static intervalDistance(minA: number, maxA: number, minB: number, maxB: any): number;
+ static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number): {
+ min: number;
+ max: number;
+ };
+ static circleToPolygon(circle: Circle, polygon: Polygon, result: CollisionResult): boolean;
+ static circleToBox(circle: Circle, box: Box, result: CollisionResult): boolean;
+ static pointToCircle(point: Vector2, circle: Circle, result: CollisionResult): boolean;
+ static pointToBox(point: Vector2, box: Box, result: CollisionResult): boolean;
+ static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
+ static pointToPoly(point: Vector2, poly: Polygon, result: CollisionResult): boolean;
+ static circleToCircle(first: Circle, second: Circle, result: CollisionResult): boolean;
+ static boxToBox(first: Box, second: Box, result: CollisionResult): boolean;
+ private static minkowskiDifference;
+ static lineToPoly(start: Vector2, end: Vector2, polygon: Polygon, hit: RaycastHit): boolean;
+ static lineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2, intersection: Vector2): boolean;
+ static lineToCircle(start: Vector2, end: Vector2, s: Circle, hit: RaycastHit): boolean;
+ static boxToBoxCast(first: Box, second: Box, movement: Vector2, hit: RaycastHit): boolean;
+ }
+}
+declare module es {
+ class SpatialHash {
+ gridBounds: Rectangle;
+ _raycastParser: RaycastResultParser;
+ _cellSize: number;
+ _inverseCellSize: number;
+ _overlapTestCircle: Circle;
+ _cellDict: NumberDictionary;
+ _tempHashSet: Collider[];
+ constructor(cellSize?: number);
+ register(collider: Collider): void;
+ remove(collider: Collider): void;
+ removeWithBruteForce(obj: Collider): void;
+ clear(): void;
+ debugDraw(secondsToDisplay: number, textScale?: number): void;
+ aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[];
+ overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number;
+ private cellCoords;
+ private cellAtPosition;
+ private debugDrawCellDetails;
+ }
+ class NumberDictionary {
+ _store: Map;
+ add(x: number, y: number, list: Collider[]): void;
+ remove(obj: Collider): void;
+ tryGetValue(x: number, y: number): Collider[];
+ clear(): void;
+ private getKey;
+ }
+ class RaycastResultParser {
+ hitCounter: number;
+ static compareRaycastHits: (a: RaycastHit, b: RaycastHit) => number;
+ _hits: RaycastHit[];
+ _tempHit: RaycastHit;
+ _checkedColliders: Collider[];
+ _cellHits: RaycastHit[];
+ _ray: Ray2D;
+ _layerMask: number;
+ start(ray: Ray2D, hits: RaycastHit[], layerMask: number): void;
+ checkRayIntersection(cellX: number, cellY: number, cell: Collider[]): boolean;
+ reset(): void;
+ }
+}
+declare class ArrayUtils {
+ static bubbleSort(ary: number[]): void;
+ static insertionSort(ary: number[]): void;
+ static binarySearch(ary: number[], value: number): number;
+ static findElementIndex(ary: any[], num: any): any;
+ static getMaxElementIndex(ary: number[]): number;
+ static getMinElementIndex(ary: number[]): number;
+ static getUniqueAry(ary: number[]): number[];
+ static getDifferAry(aryA: number[], aryB: number[]): number[];
+ static swap(array: any[], index1: number, index2: number): void;
+ static clearList(ary: any[]): void;
+ static cloneList(ary: any[]): any[];
+ static equals(ary1: number[], ary2: number[]): Boolean;
+ static insert(ary: any[], index: number, value: any): any;
+}
+declare class Base64Utils {
+ private static _keyNum;
+ private static _keyStr;
+ private static _keyAll;
+ static encode: (input: any) => string;
+ static decode(input: any, isNotStr?: boolean): string;
+ private static _utf8_encode;
+ private static _utf8_decode;
+ private static getConfKey;
+}
+declare module es {
+ class ContentManager {
+ protected loadedAssets: Map;
+ loadRes(name: string, local?: boolean): Promise;
+ dispose(): void;
+ }
+}
+declare module es {
+ class DrawUtils {
+ static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness?: number): void;
+ static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness?: number): void;
+ static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness?: number): void;
+ static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness?: number): void;
+ static drawPixel(shape: egret.Shape, position: Vector2, color: number, size?: number): void;
+ static getColorMatrix(color: number): egret.ColorMatrixFilter;
+ }
+}
+declare module es {
+ class FuncPack {
+ func: Function;
+ context: any;
+ constructor(func: Function, context: any);
+ }
+ class Emitter {
+ private _messageTable;
+ constructor();
+ addObserver(eventType: T, handler: Function, context: any): void;
+ removeObserver(eventType: T, handler: Function): void;
+ emit(eventType: T, data?: any): void;
+ }
+}
+declare module es {
+ class GlobalManager {
+ _enabled: boolean;
+ enabled: boolean;
+ setEnabled(isEnabled: boolean): void;
+ onEnabled(): void;
+ onDisabled(): void;
+ update(): void;
+ }
+}
+declare module es {
+ class TouchState {
+ x: number;
+ y: number;
+ touchPoint: number;
+ touchDown: boolean;
+ readonly position: Vector2;
+ reset(): void;
+ }
+ class Input {
+ private static _init;
+ private static _previousTouchState;
+ private static _resolutionOffset;
+ private static _touchIndex;
+ private static _gameTouchs;
+ static readonly gameTouchs: TouchState[];
+ private static _resolutionScale;
+ static readonly resolutionScale: Vector2;
+ private static _totalTouchCount;
+ static readonly totalTouchCount: number;
+ static readonly touchPosition: Vector2;
+ static maxSupportedTouch: number;
+ static readonly touchPositionDelta: Vector2;
+ static initialize(): void;
+ static scaledPosition(position: Vector2): Vector2;
+ private static initTouchCache;
+ private static touchBegin;
+ private static touchMove;
+ private static touchEnd;
+ private static setpreviousTouchState;
+ }
+}
+declare class KeyboardUtils {
+ static TYPE_KEY_DOWN: number;
+ static TYPE_KEY_UP: number;
+ static A: string;
+ static B: string;
+ static C: string;
+ static D: string;
+ static E: string;
+ static F: string;
+ static G: string;
+ static H: string;
+ static I: string;
+ static J: string;
+ static K: string;
+ static L: string;
+ static M: string;
+ static N: string;
+ static O: string;
+ static P: string;
+ static Q: string;
+ static R: string;
+ static S: string;
+ static T: string;
+ static U: string;
+ static V: string;
+ static W: string;
+ static X: string;
+ static Y: string;
+ static Z: string;
+ static ESC: string;
+ static F1: string;
+ static F2: string;
+ static F3: string;
+ static F4: string;
+ static F5: string;
+ static F6: string;
+ static F7: string;
+ static F8: string;
+ static F9: string;
+ static F10: string;
+ static F11: string;
+ static F12: string;
+ static NUM_1: string;
+ static NUM_2: string;
+ static NUM_3: string;
+ static NUM_4: string;
+ static NUM_5: string;
+ static NUM_6: string;
+ static NUM_7: string;
+ static NUM_8: string;
+ static NUM_9: string;
+ static NUM_0: string;
+ static TAB: string;
+ static CTRL: string;
+ static ALT: string;
+ static SHIFT: string;
+ static CAPS_LOCK: string;
+ static ENTER: string;
+ static SPACE: string;
+ static BACK_SPACE: string;
+ static INSERT: string;
+ static DELETE: string;
+ static HOME: string;
+ static END: string;
+ static PAGE_UP: string;
+ static PAGE_DOWN: string;
+ static LEFT: string;
+ static RIGHT: string;
+ static UP: string;
+ static DOWN: string;
+ static PAUSE_BREAK: string;
+ static NUM_LOCK: string;
+ static SCROLL_LOCK: string;
+ static WINDOWS: string;
+ private static keyDownDict;
+ private static keyUpDict;
+ static init(): void;
+ static registerKey(key: string, fun: Function, thisObj: any, type?: number, ...args: any[]): void;
+ static unregisterKey(key: string, type?: number): void;
+ static destroy(): void;
+ private static onKeyDonwHander;
+ private static onKeyUpHander;
+ private static keyCodeToString;
+}
+declare module es {
+ class ListPool {
+ private static readonly _objectQueue;
+ static warmCache(cacheCount: number): void;
+ static trimCache(cacheCount: any): void;
+ static clearCache(): void;
+ static obtain(): T[];
+ static free(obj: Array): void;
+ }
+}
+declare const THREAD_ID: string;
+declare const nextTick: (fn: any) => void;
+declare class LockUtils {
+ private _keyX;
+ private _keyY;
+ private setItem;
+ private getItem;
+ private removeItem;
+ constructor(key: any);
+ lock(): Promise<{}>;
+}
+declare module es {
+ class Pair {
+ first: T;
+ second: T;
+ constructor(first: T, second: T);
+ clear(): void;
+ equals(other: Pair): boolean;
+ }
+}
+declare class RandomUtils {
+ static randrange(start: number, stop: number, step?: number): number;
+ static randint(a: number, b: number): number;
+ static randnum(a: number, b: number): number;
+ static shuffle(array: any[]): any[];
+ static choice(sequence: any): any;
+ static sample(sequence: any[], num: number): any[];
+ static random(): number;
+ static boolean(chance?: number): boolean;
+ private static _randomCompare;
+}
+declare module es {
+ class RectangleExt {
+ static union(first: Rectangle, point: Vector2): Rectangle;
+ }
+}
+declare module es {
+ class Triangulator {
+ triangleIndices: number[];
+ private _triPrev;
+ private _triNext;
+ static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean;
+ triangulate(points: Vector2[], arePointsCCW?: boolean): void;
+ private initialize;
+ }
+}
+declare module es {
+ class Vector2Ext {
+ static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean;
+ static cross(u: Vector2, v: Vector2): number;
+ static perpendicular(first: Vector2, second: Vector2): Vector2;
+ static normalize(vec: Vector2): Vector2;
+ static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void;
+ static transformR(position: Vector2, matrix: Matrix2D): Vector2;
+ static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void;
+ static round(vec: Vector2): Vector2;
+ }
+}
+declare class WebGLUtils {
+ static getContext(): CanvasRenderingContext2D;
+}
+declare module es {
+ class Layout {
+ clientArea: Rectangle;
+ safeArea: Rectangle;
+ constructor();
+ place(size: Vector2, horizontalMargin: number, verticalMargine: number, alignment: Alignment): Rectangle;
+ }
+ enum Alignment {
+ none = 0,
+ left = 1,
+ right = 2,
+ horizontalCenter = 4,
+ top = 8,
+ bottom = 16,
+ verticalCenter = 32,
+ topLeft = 9,
+ topRight = 10,
+ topCenter = 12,
+ bottomLeft = 17,
+ bottomRight = 18,
+ bottomCenter = 20,
+ centerLeft = 33,
+ centerRight = 34,
+ center = 36
+ }
+}
+declare namespace stopwatch {
+ class Stopwatch {
+ private readonly getSystemTime;
+ private _startSystemTime;
+ private _stopSystemTime;
+ private _stopDuration;
+ private _pendingSliceStartStopwatchTime;
+ private _completeSlices;
+ constructor(getSystemTime?: GetTimeFunc);
+ getState(): State;
+ isIdle(): boolean;
+ isRunning(): boolean;
+ isStopped(): boolean;
+ slice(): Slice;
+ getCompletedSlices(): Slice[];
+ getCompletedAndPendingSlices(): Slice[];
+ getPendingSlice(): Slice;
+ getTime(): number;
+ reset(): void;
+ start(forceReset?: boolean): void;
+ stop(recordPendingSlice?: boolean): number;
+ private calculatePendingSlice;
+ private caculateStopwatchTime;
+ private getSystemTimeOfCurrentStopwatchTime;
+ private recordPendingSlice;
+ }
+ type GetTimeFunc = () => number;
+ enum State {
+ IDLE = "IDLE",
+ RUNNING = "RUNNING",
+ STOPPED = "STOPPED"
+ }
+ function setDefaultSystemTimeGetter(systemTimeGetter?: GetTimeFunc): void;
+ interface Slice {
+ readonly startTime: number;
+ readonly endTime: number;
+ readonly duration: number;
+ }
+}
+declare module es {
+ class TimeRuler {
+ static readonly maxBars: number;
+ static readonly maxSamples: number;
+ static readonly maxNestCall: number;
+ static readonly barHeight: number;
+ static readonly maxSampleFrames: number;
+ static readonly logSnapDuration: number;
+ static readonly barPadding: number;
+ static readonly autoAdjustDelay: number;
+ private static _instance;
+ targetSampleFrames: number;
+ width: number;
+ enabled: true;
+ showLog: boolean;
+ private _frameKey;
+ private _logKey;
+ private _logs;
+ private sampleFrames;
+ private _position;
+ private _prevLog;
+ private _curLog;
+ private frameCount;
+ private markers;
+ private stopwacth;
+ private _markerNameToIdMap;
+ private _updateCount;
+ private _frameAdjust;
+ constructor();
+ static readonly Instance: TimeRuler;
+ startFrame(): void;
+ beginMark(markerName: string, color: number, barIndex?: number): void;
+ endMark(markerName: string, barIndex?: number): void;
+ getAverageTime(barIndex: number, markerName: string): number;
+ resetLog(): void;
+ render(position?: Vector2, width?: number): void;
+ private onGraphicsDeviceReset;
+ }
+ class FrameLog {
+ bars: MarkerCollection[];
+ constructor();
+ }
+ class MarkerCollection {
+ markers: Marker[];
+ markCount: number;
+ markerNests: number[];
+ nestCount: number;
+ constructor();
+ }
+ class Marker {
+ markerId: number;
+ beginTime: number;
+ endTime: number;
+ color: number;
+ }
+ class MarkerInfo {
+ name: string;
+ logs: MarkerLog[];
+ constructor(name: any);
+ }
+ class MarkerLog {
+ snapMin: number;
+ snapMax: number;
+ snapAvg: number;
min: number;
max: number;
- };
- static circleToPolygon(circle: Circle, polygon: Polygon): CollisionResult;
- static circleToBox(circle: Circle, box: Box): CollisionResult;
- static pointToCircle(point: Vector2, circle: Circle): CollisionResult;
- static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
- static pointToPoly(point: Vector2, poly: Polygon): CollisionResult;
- static circleToCircle(first: Circle, second: Circle): CollisionResult;
- static boxToBox(first: Box, second: Box): CollisionResult;
- private static minkowskiDifference;
-}
-declare class SpatialHash {
- gridBounds: Rectangle;
- private _raycastParser;
- private _cellSize;
- private _inverseCellSize;
- private _overlapTestCircle;
- private _tempHashSet;
- private _cellDict;
- constructor(cellSize?: number);
- remove(collider: Collider): void;
- register(collider: Collider): void;
- clear(): void;
- overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number;
- aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): {
- tempHashSet: Collider[];
- bounds: Rectangle;
- };
- private cellAtPosition;
- private cellCoords;
-}
-declare class RaycastResultParser {
-}
-declare class NumberDictionary {
- private _store;
- private getKey;
- private intToUint;
- add(x: number, y: number, list: Collider[]): void;
- remove(obj: Collider): void;
- tryGetValue(x: number, y: number): Collider[];
- clear(): void;
-}
-declare class fui {
-}
-declare class ContentManager {
- protected loadedAssets: Map;
- loadRes(name: string, local?: boolean): Promise;
- dispose(): void;
-}
-declare class Emitter {
- private _messageTable;
- constructor();
- addObserver(eventType: T, handler: Function): void;
- removeObserver(eventType: T, handler: Function): void;
- emit(eventType: T, data: any): void;
-}
-declare class GlobalManager {
- static globalManagers: GlobalManager[];
- private _enabled;
- enabled: boolean;
- setEnabled(isEnabled: boolean): void;
- onEnabled(): void;
- onDisabled(): void;
- update(): void;
- static registerGlobalManager(manager: GlobalManager): void;
- static unregisterGlobalManager(manager: GlobalManager): void;
- static getGlobalManager(type: any): T;
-}
-declare class TouchState {
- x: number;
- y: number;
- touchPoint: number;
- touchDown: boolean;
- readonly position: Vector2;
- reset(): void;
-}
-declare class Input {
- private static _init;
- private static _stage;
- private static _previousTouchState;
- private static _gameTouchs;
- private static _resolutionOffset;
- private static _resolutionScale;
- private static _touchIndex;
- private static _totalTouchCount;
- static readonly touchPosition: Vector2;
- static maxSupportedTouch: number;
- static readonly resolutionScale: Vector2;
- static readonly totalTouchCount: number;
- static readonly gameTouchs: TouchState[];
- static readonly touchPositionDelta: Vector2;
- static initialize(stage: egret.Stage): void;
- private static initTouchCache;
- private static touchBegin;
- private static touchMove;
- private static touchEnd;
- private static setpreviousTouchState;
- static scaledPosition(position: Vector2): Vector2;
-}
-declare class ListPool {
- private static readonly _objectQueue;
- static warmCache(cacheCount: number): void;
- static trimCache(cacheCount: any): void;
- static clearCache(): void;
- static obtain(): Array;
- static free(obj: Array): void;
-}
-declare class Pair {
- first: T;
- second: T;
- constructor(first: T, second: T);
- clear(): void;
- equals(other: Pair): boolean;
-}
-declare class RectangleExt {
- static union(first: Rectangle, point: Vector2): Rectangle;
- static unionR(value1: Rectangle, value2: Rectangle): Rectangle;
-}
-declare class Triangulator {
- triangleIndices: number[];
- private _triPrev;
- private _triNext;
- triangulate(points: Vector2[], arePointsCCW?: boolean): void;
- private initialize;
- static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean;
-}
-declare class Vector2Ext {
- static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean;
- static cross(u: Vector2, v: Vector2): number;
- static perpendicular(first: Vector2, second: Vector2): Vector2;
- static normalize(vec: Vector2): Vector2;
- static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void;
- static transformR(position: Vector2, matrix: Matrix2D): Vector2;
- static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void;
- static round(vec: Vector2): Vector2;
+ avg: number;
+ samples: number;
+ color: number;
+ initialized: boolean;
+ }
}
diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js
index fb3d7c1e..a1ee37aa 100644
--- a/demo/libs/framework/framework.js
+++ b/demo/libs/framework/framework.js
@@ -111,6 +111,10 @@ Array.prototype.findAll = function (predicate) {
Array.prototype.contains = function (value) {
function contains(array, value) {
for (var i = 0, len = array.length; i < len; i++) {
+ if (array[i] instanceof egret.HashObject && value instanceof egret.HashObject) {
+ if (array[i].hashCode == value.hashCode)
+ return true;
+ }
if (array[i] == value) {
return true;
}
@@ -214,7 +218,9 @@ Array.prototype.groupBy = function (keySelector) {
var keys_1 = [];
return array.reduce(function (groups, element, index) {
var key = JSON.stringify(keySelector.call(arguments[1], element, index, array));
- var index2 = keys_1.findIndex(function (x) { return x === key; });
+ var index2 = keys_1.findIndex(function (x) {
+ return x === key;
+ });
if (index2 < 0) {
index2 = keys_1.push(key) - 1;
}
@@ -230,7 +236,9 @@ Array.prototype.groupBy = function (keySelector) {
var keys = [];
var _loop_1 = function (i, len) {
var key = JSON.stringify(keySelector.call(arguments_1[1], array[i], i, array));
- var index = keys.findIndex(function (x) { return x === key; });
+ var index = keys.findIndex(function (x) {
+ return x === key;
+ });
if (index < 0) {
index = keys.push(key) - 1;
}
@@ -273,2961 +281,4635 @@ Array.prototype.sum = function (selector) {
}
return sum(this, selector);
};
-var PriorityQueueNode = (function () {
- function PriorityQueueNode() {
- this.priority = 0;
- this.insertionIndex = 0;
- this.queueIndex = 0;
- }
- return PriorityQueueNode;
-}());
-var AStarPathfinder = (function () {
- function AStarPathfinder() {
- }
- AStarPathfinder.search = function (graph, start, goal) {
- var _this = this;
- var foundPath = false;
- var cameFrom = new Map();
- cameFrom.set(start, start);
- var costSoFar = new Map();
- var frontier = new PriorityQueue(1000);
- frontier.enqueue(new AStarNode(start), 0);
- costSoFar.set(start, 0);
- var _loop_2 = function () {
- var current = frontier.dequeue();
- if (JSON.stringify(current.data) == JSON.stringify(goal)) {
- foundPath = true;
- return "break";
- }
- graph.getNeighbors(current.data).forEach(function (next) {
- var newCost = costSoFar.get(current.data) + graph.cost(current.data, next);
- if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) {
- costSoFar.set(next, newCost);
- var priority = newCost + graph.heuristic(next, goal);
- frontier.enqueue(new AStarNode(next), priority);
- cameFrom.set(next, current.data);
+var es;
+(function (es) {
+ var PriorityQueueNode = (function () {
+ function PriorityQueueNode() {
+ this.priority = 0;
+ this.insertionIndex = 0;
+ this.queueIndex = 0;
+ }
+ return PriorityQueueNode;
+ }());
+ es.PriorityQueueNode = PriorityQueueNode;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var AStarPathfinder = (function () {
+ function AStarPathfinder() {
+ }
+ AStarPathfinder.search = function (graph, start, goal) {
+ var _this = this;
+ var foundPath = false;
+ var cameFrom = new Map();
+ cameFrom.set(start, start);
+ var costSoFar = new Map();
+ var frontier = new es.PriorityQueue(1000);
+ frontier.enqueue(new AStarNode(start), 0);
+ costSoFar.set(start, 0);
+ var _loop_2 = function () {
+ var current = frontier.dequeue();
+ if (JSON.stringify(current.data) == JSON.stringify(goal)) {
+ foundPath = true;
+ return "break";
}
- });
+ graph.getNeighbors(current.data).forEach(function (next) {
+ var newCost = costSoFar.get(current.data) + graph.cost(current.data, next);
+ if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) {
+ costSoFar.set(next, newCost);
+ var priority = newCost + graph.heuristic(next, goal);
+ frontier.enqueue(new AStarNode(next), priority);
+ cameFrom.set(next, current.data);
+ }
+ });
+ };
+ while (frontier.count > 0) {
+ var state_1 = _loop_2();
+ if (state_1 === "break")
+ break;
+ }
+ return foundPath ? this.recontructPath(cameFrom, start, goal) : null;
};
- while (frontier.count > 0) {
- var state_1 = _loop_2();
- if (state_1 === "break")
- break;
+ AStarPathfinder.recontructPath = function (cameFrom, start, goal) {
+ var path = [];
+ var current = goal;
+ path.push(goal);
+ while (current != start) {
+ current = this.getKey(cameFrom, current);
+ path.push(current);
+ }
+ path.reverse();
+ return path;
+ };
+ AStarPathfinder.hasKey = function (map, compareKey) {
+ var iterator = map.keys();
+ var r;
+ while (r = iterator.next(), !r.done) {
+ if (JSON.stringify(r.value) == JSON.stringify(compareKey))
+ return true;
+ }
+ return false;
+ };
+ AStarPathfinder.getKey = function (map, compareKey) {
+ var iterator = map.keys();
+ var valueIterator = map.values();
+ var r;
+ var v;
+ while (r = iterator.next(), v = valueIterator.next(), !r.done) {
+ if (JSON.stringify(r.value) == JSON.stringify(compareKey))
+ return v.value;
+ }
+ return null;
+ };
+ return AStarPathfinder;
+ }());
+ es.AStarPathfinder = AStarPathfinder;
+ var AStarNode = (function (_super) {
+ __extends(AStarNode, _super);
+ function AStarNode(data) {
+ var _this = _super.call(this) || this;
+ _this.data = data;
+ return _this;
}
- return foundPath ? this.recontructPath(cameFrom, start, goal) : null;
- };
- AStarPathfinder.hasKey = function (map, compareKey) {
- var iterator = map.keys();
- var r;
- while (r = iterator.next(), !r.done) {
- if (JSON.stringify(r.value) == JSON.stringify(compareKey))
- return true;
+ return AStarNode;
+ }(es.PriorityQueueNode));
+ es.AStarNode = AStarNode;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var AstarGridGraph = (function () {
+ function AstarGridGraph(width, height) {
+ this.dirs = [
+ new es.Vector2(1, 0),
+ new es.Vector2(0, -1),
+ new es.Vector2(-1, 0),
+ new es.Vector2(0, 1)
+ ];
+ this.walls = [];
+ this.weightedNodes = [];
+ this.defaultWeight = 1;
+ this.weightedNodeWeight = 5;
+ this._neighbors = new Array(4);
+ this._width = width;
+ this._height = height;
}
- return false;
- };
- AStarPathfinder.getKey = function (map, compareKey) {
- var iterator = map.keys();
- var valueIterator = map.values();
- var r;
- var v;
- while (r = iterator.next(), v = valueIterator.next(), !r.done) {
- if (JSON.stringify(r.value) == JSON.stringify(compareKey))
- return v.value;
+ AstarGridGraph.prototype.isNodeInBounds = function (node) {
+ return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
+ };
+ AstarGridGraph.prototype.isNodePassable = function (node) {
+ return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); });
+ };
+ AstarGridGraph.prototype.search = function (start, goal) {
+ return es.AStarPathfinder.search(this, start, goal);
+ };
+ AstarGridGraph.prototype.getNeighbors = function (node) {
+ var _this = this;
+ this._neighbors.length = 0;
+ this.dirs.forEach(function (dir) {
+ var next = new es.Vector2(node.x + dir.x, node.y + dir.y);
+ if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
+ _this._neighbors.push(next);
+ });
+ return this._neighbors;
+ };
+ AstarGridGraph.prototype.cost = function (from, to) {
+ return this.weightedNodes.find(function (p) { return JSON.stringify(p) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight;
+ };
+ AstarGridGraph.prototype.heuristic = function (node, goal) {
+ return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y);
+ };
+ return AstarGridGraph;
+ }());
+ es.AstarGridGraph = AstarGridGraph;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var PriorityQueue = (function () {
+ function PriorityQueue(maxNodes) {
+ this._numNodes = 0;
+ this._nodes = new Array(maxNodes + 1);
+ this._numNodesEverEnqueued = 0;
}
- return null;
- };
- AStarPathfinder.recontructPath = function (cameFrom, start, goal) {
- var path = [];
- var current = goal;
- path.push(goal);
- while (current != start) {
- current = this.getKey(cameFrom, current);
- path.push(current);
- }
- path.reverse();
- return path;
- };
- return AStarPathfinder;
-}());
-var AStarNode = (function (_super) {
- __extends(AStarNode, _super);
- function AStarNode(data) {
- var _this = _super.call(this) || this;
- _this.data = data;
- return _this;
- }
- return AStarNode;
-}(PriorityQueueNode));
-var AstarGridGraph = (function () {
- function AstarGridGraph(width, height) {
- this.dirs = [
- new Vector2(1, 0),
- new Vector2(0, -1),
- new Vector2(-1, 0),
- new Vector2(0, 1)
- ];
- this.walls = [];
- this.weightedNodes = [];
- this.defaultWeight = 1;
- this.weightedNodeWeight = 5;
- this._neighbors = new Array(4);
- this._width = width;
- this._height = height;
- }
- AstarGridGraph.prototype.isNodeInBounds = function (node) {
- return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
- };
- AstarGridGraph.prototype.isNodePassable = function (node) {
- return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); });
- };
- AstarGridGraph.prototype.search = function (start, goal) {
- return AStarPathfinder.search(this, start, goal);
- };
- AstarGridGraph.prototype.getNeighbors = function (node) {
- var _this = this;
- this._neighbors.length = 0;
- this.dirs.forEach(function (dir) {
- var next = new Vector2(node.x + dir.x, node.y + dir.y);
- if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
- _this._neighbors.push(next);
+ Object.defineProperty(PriorityQueue.prototype, "count", {
+ get: function () {
+ return this._numNodes;
+ },
+ enumerable: true,
+ configurable: true
});
- return this._neighbors;
- };
- AstarGridGraph.prototype.cost = function (from, to) {
- return this.weightedNodes.find(function (p) { return JSON.stringify(p) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight;
- };
- AstarGridGraph.prototype.heuristic = function (node, goal) {
- return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y);
- };
- return AstarGridGraph;
-}());
-var PriorityQueue = (function () {
- function PriorityQueue(maxNodes) {
- this._numNodes = 0;
- this._nodes = new Array(maxNodes + 1);
- this._numNodesEverEnqueued = 0;
- }
- PriorityQueue.prototype.clear = function () {
- this._nodes.splice(1, this._numNodes);
- this._numNodes = 0;
- };
- Object.defineProperty(PriorityQueue.prototype, "count", {
- get: function () {
- return this._numNodes;
- },
- enumerable: true,
- configurable: true
- });
- PriorityQueue.prototype.contains = function (node) {
- return (this._nodes[node.queueIndex] == node);
- };
- PriorityQueue.prototype.enqueue = function (node, priority) {
- node.priority = priority;
- this._numNodes++;
- this._nodes[this._numNodes] = node;
- node.queueIndex = this._numNodes;
- node.insertionIndex = this._numNodesEverEnqueued++;
- this.cascadeUp(this._nodes[this._numNodes]);
- };
- PriorityQueue.prototype.dequeue = function () {
- var returnMe = this._nodes[1];
- this.remove(returnMe);
- return returnMe;
- };
- PriorityQueue.prototype.remove = function (node) {
- if (node.queueIndex == this._numNodes) {
- this._nodes[this._numNodes] = null;
+ Object.defineProperty(PriorityQueue.prototype, "maxSize", {
+ get: function () {
+ return this._nodes.length - 1;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ PriorityQueue.prototype.clear = function () {
+ this._nodes.splice(1, this._numNodes);
+ this._numNodes = 0;
+ };
+ PriorityQueue.prototype.contains = function (node) {
+ if (!node) {
+ console.error("node cannot be null");
+ return false;
+ }
+ if (node.queueIndex < 0 || node.queueIndex >= this._nodes.length) {
+ console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?");
+ return false;
+ }
+ return (this._nodes[node.queueIndex] == node);
+ };
+ PriorityQueue.prototype.enqueue = function (node, priority) {
+ node.priority = priority;
+ this._numNodes++;
+ this._nodes[this._numNodes] = node;
+ node.queueIndex = this._numNodes;
+ node.insertionIndex = this._numNodesEverEnqueued++;
+ this.cascadeUp(this._nodes[this._numNodes]);
+ };
+ PriorityQueue.prototype.dequeue = function () {
+ var returnMe = this._nodes[1];
+ this.remove(returnMe);
+ return returnMe;
+ };
+ PriorityQueue.prototype.remove = function (node) {
+ if (node.queueIndex == this._numNodes) {
+ this._nodes[this._numNodes] = null;
+ this._numNodes--;
+ return;
+ }
+ var formerLastNode = this._nodes[this._numNodes];
+ this.swap(node, formerLastNode);
+ delete this._nodes[this._numNodes];
this._numNodes--;
- return;
- }
- var formerLastNode = this._nodes[this._numNodes];
- this.swap(node, formerLastNode);
- delete this._nodes[this._numNodes];
- this._numNodes--;
- this.onNodeUpdated(formerLastNode);
- };
- PriorityQueue.prototype.isValidQueue = function () {
- for (var i = 1; i < this._nodes.length; i++) {
- if (this._nodes[i]) {
- var childLeftIndex = 2 * i;
- if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] &&
- this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i]))
- return false;
+ this.onNodeUpdated(formerLastNode);
+ };
+ PriorityQueue.prototype.isValidQueue = function () {
+ for (var i = 1; i < this._nodes.length; i++) {
+ if (this._nodes[i]) {
+ var childLeftIndex = 2 * i;
+ if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] &&
+ this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i]))
+ return false;
+ var childRightIndex = childLeftIndex + 1;
+ if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] &&
+ this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i]))
+ return false;
+ }
+ }
+ return true;
+ };
+ PriorityQueue.prototype.onNodeUpdated = function (node) {
+ var parentIndex = Math.floor(node.queueIndex / 2);
+ var parentNode = this._nodes[parentIndex];
+ if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) {
+ this.cascadeUp(node);
+ }
+ else {
+ this.cascadeDown(node);
+ }
+ };
+ PriorityQueue.prototype.cascadeDown = function (node) {
+ var newParent;
+ var finalQueueIndex = node.queueIndex;
+ while (true) {
+ newParent = node;
+ var childLeftIndex = 2 * finalQueueIndex;
+ if (childLeftIndex > this._numNodes) {
+ node.queueIndex = finalQueueIndex;
+ this._nodes[finalQueueIndex] = node;
+ break;
+ }
+ var childLeft = this._nodes[childLeftIndex];
+ if (this.hasHigherPriority(childLeft, newParent)) {
+ newParent = childLeft;
+ }
var childRightIndex = childLeftIndex + 1;
- if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] &&
- this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i]))
- return false;
- }
- }
- return true;
- };
- PriorityQueue.prototype.onNodeUpdated = function (node) {
- var parentIndex = Math.floor(node.queueIndex / 2);
- var parentNode = this._nodes[parentIndex];
- if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) {
- this.cascadeUp(node);
- }
- else {
- this.cascadeDown(node);
- }
- };
- PriorityQueue.prototype.cascadeDown = function (node) {
- var newParent;
- var finalQueueIndex = node.queueIndex;
- while (true) {
- newParent = node;
- var childLeftIndex = 2 * finalQueueIndex;
- if (childLeftIndex > this._numNodes) {
- node.queueIndex = finalQueueIndex;
- this._nodes[finalQueueIndex] = node;
- break;
- }
- var childLeft = this._nodes[childLeftIndex];
- if (this.hasHigherPriority(childLeft, newParent)) {
- newParent = childLeft;
- }
- var childRightIndex = childLeftIndex + 1;
- if (childRightIndex <= this._numNodes) {
- var childRight = this._nodes[childRightIndex];
- if (this.hasHigherPriority(childRight, newParent)) {
- newParent = childRight;
+ if (childRightIndex <= this._numNodes) {
+ var childRight = this._nodes[childRightIndex];
+ if (this.hasHigherPriority(childRight, newParent)) {
+ newParent = childRight;
+ }
+ }
+ if (newParent != node) {
+ this._nodes[finalQueueIndex] = newParent;
+ var temp = newParent.queueIndex;
+ newParent.queueIndex = finalQueueIndex;
+ finalQueueIndex = temp;
+ }
+ else {
+ node.queueIndex = finalQueueIndex;
+ this._nodes[finalQueueIndex] = node;
+ break;
}
}
- if (newParent != node) {
- this._nodes[finalQueueIndex] = newParent;
- var temp = newParent.queueIndex;
- newParent.queueIndex = finalQueueIndex;
- finalQueueIndex = temp;
- }
- else {
- node.queueIndex = finalQueueIndex;
- this._nodes[finalQueueIndex] = node;
- break;
- }
- }
- };
- PriorityQueue.prototype.cascadeUp = function (node) {
- var parent = Math.floor(node.queueIndex / 2);
- while (parent >= 1) {
- var parentNode = this._nodes[parent];
- if (this.hasHigherPriority(parentNode, node))
- break;
- this.swap(node, parentNode);
- parent = Math.floor(node.queueIndex / 2);
- }
- };
- PriorityQueue.prototype.swap = function (node1, node2) {
- this._nodes[node1.queueIndex] = node2;
- this._nodes[node2.queueIndex] = node1;
- var temp = node1.queueIndex;
- node1.queueIndex = node2.queueIndex;
- node2.queueIndex = temp;
- };
- PriorityQueue.prototype.hasHigherPriority = function (higher, lower) {
- return (higher.priority < lower.priority ||
- (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex));
- };
- return PriorityQueue;
-}());
-var BreadthFirstPathfinder = (function () {
- function BreadthFirstPathfinder() {
- }
- BreadthFirstPathfinder.search = function (graph, start, goal) {
- var _this = this;
- var foundPath = false;
- var frontier = [];
- frontier.unshift(start);
- var cameFrom = new Map();
- cameFrom.set(start, start);
- var _loop_3 = function () {
- var current = frontier.shift();
- if (JSON.stringify(current) == JSON.stringify(goal)) {
- foundPath = true;
- return "break";
- }
- graph.getNeighbors(current).forEach(function (next) {
- if (!_this.hasKey(cameFrom, next)) {
- frontier.unshift(next);
- cameFrom.set(next, current);
- }
- });
};
- while (frontier.length > 0) {
- var state_2 = _loop_3();
- if (state_2 === "break")
- break;
- }
- return foundPath ? AStarPathfinder.recontructPath(cameFrom, start, goal) : null;
- };
- BreadthFirstPathfinder.hasKey = function (map, compareKey) {
- var iterator = map.keys();
- var r;
- while (r = iterator.next(), !r.done) {
- if (JSON.stringify(r.value) == JSON.stringify(compareKey))
- return true;
- }
- return false;
- };
- return BreadthFirstPathfinder;
-}());
-var UnweightedGraph = (function () {
- function UnweightedGraph() {
- this.edges = new Map();
- }
- UnweightedGraph.prototype.addEdgesForNode = function (node, edges) {
- this.edges.set(node, edges);
- return this;
- };
- UnweightedGraph.prototype.getNeighbors = function (node) {
- return this.edges.get(node);
- };
- return UnweightedGraph;
-}());
-var Vector2 = (function () {
- function Vector2(x, y) {
- this.x = 0;
- this.y = 0;
- this.x = x ? x : 0;
- this.y = y ? y : this.x;
- }
- Object.defineProperty(Vector2, "zero", {
- get: function () {
- return Vector2.zeroVector2;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Vector2, "one", {
- get: function () {
- return Vector2.unitVector2;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Vector2, "unitX", {
- get: function () {
- return Vector2.unitXVector;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Vector2, "unitY", {
- get: function () {
- return Vector2.unitYVector;
- },
- enumerable: true,
- configurable: true
- });
- Vector2.add = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x + value2.x;
- result.y = value1.y + value2.y;
- return result;
- };
- Vector2.divide = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x / value2.x;
- result.y = value1.y / value2.y;
- return result;
- };
- Vector2.multiply = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x * value2.x;
- result.y = value1.y * value2.y;
- return result;
- };
- Vector2.subtract = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x - value2.x;
- result.y = value1.y - value2.y;
- return result;
- };
- Vector2.prototype.normalize = function () {
- var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y));
- this.x *= val;
- this.y *= val;
- };
- Vector2.prototype.length = function () {
- return Math.sqrt((this.x * this.x) + (this.y * this.y));
- };
- Vector2.prototype.round = function () {
- return new Vector2(Math.round(this.x), Math.round(this.y));
- };
- Vector2.normalize = function (value) {
- var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y));
- value.x *= val;
- value.y *= val;
- return value;
- };
- Vector2.dot = function (value1, value2) {
- return (value1.x * value2.x) + (value1.y * value2.y);
- };
- Vector2.distanceSquared = function (value1, value2) {
- var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
- return (v1 * v1) + (v2 * v2);
- };
- Vector2.clamp = function (value1, min, max) {
- return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), MathHelper.clamp(value1.y, min.y, max.y));
- };
- Vector2.lerp = function (value1, value2, amount) {
- return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount));
- };
- Vector2.transform = function (position, matrix) {
- return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22));
- };
- Vector2.distance = function (value1, value2) {
- var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
- return Math.sqrt((v1 * v1) + (v2 * v2));
- };
- Vector2.negate = function (value) {
- var result = new Vector2();
- result.x = -value.x;
- result.y = -value.y;
- return result;
- };
- Vector2.unitYVector = new Vector2(0, 1);
- Vector2.unitXVector = new Vector2(1, 0);
- Vector2.unitVector2 = new Vector2(1, 1);
- Vector2.zeroVector2 = new Vector2(0, 0);
- return Vector2;
-}());
-var UnweightedGridGraph = (function () {
- function UnweightedGridGraph(width, height, allowDiagonalSearch) {
- if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; }
- this.walls = [];
- this._neighbors = new Array(4);
- this._width = width;
- this._hegiht = height;
- this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS;
- }
- UnweightedGridGraph.prototype.isNodeInBounds = function (node) {
- return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht;
- };
- UnweightedGridGraph.prototype.isNodePassable = function (node) {
- return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); });
- };
- UnweightedGridGraph.prototype.getNeighbors = function (node) {
- var _this = this;
- this._neighbors.length = 0;
- this._dirs.forEach(function (dir) {
- var next = new Vector2(node.x + dir.x, node.y + dir.y);
- if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
- _this._neighbors.push(next);
- });
- return this._neighbors;
- };
- UnweightedGridGraph.prototype.search = function (start, goal) {
- return BreadthFirstPathfinder.search(this, start, goal);
- };
- UnweightedGridGraph.CARDINAL_DIRS = [
- new Vector2(1, 0),
- new Vector2(0, -1),
- new Vector2(-1, 0),
- new Vector2(0, -1)
- ];
- UnweightedGridGraph.COMPASS_DIRS = [
- new Vector2(1, 0),
- new Vector2(1, -1),
- new Vector2(0, -1),
- new Vector2(-1, -1),
- new Vector2(-1, 0),
- new Vector2(-1, 1),
- new Vector2(0, 1),
- new Vector2(1, 1),
- ];
- return UnweightedGridGraph;
-}());
-var WeightedGridGraph = (function () {
- function WeightedGridGraph(width, height, allowDiagonalSearch) {
- if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; }
- this.walls = [];
- this.weightedNodes = [];
- this.defaultWeight = 1;
- this.weightedNodeWeight = 5;
- this._neighbors = new Array(4);
- this._width = width;
- this._height = height;
- this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS;
- }
- WeightedGridGraph.prototype.isNodeInBounds = function (node) {
- return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
- };
- WeightedGridGraph.prototype.isNodePassable = function (node) {
- return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); });
- };
- WeightedGridGraph.prototype.search = function (start, goal) {
- return WeightedPathfinder.search(this, start, goal);
- };
- WeightedGridGraph.prototype.getNeighbors = function (node) {
- var _this = this;
- this._neighbors.length = 0;
- this._dirs.forEach(function (dir) {
- var next = new Vector2(node.x + dir.x, node.y + dir.y);
- if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
- _this._neighbors.push(next);
- });
- return this._neighbors;
- };
- WeightedGridGraph.prototype.cost = function (from, to) {
- return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight;
- };
- WeightedGridGraph.CARDINAL_DIRS = [
- new Vector2(1, 0),
- new Vector2(0, -1),
- new Vector2(-1, 0),
- new Vector2(0, 1)
- ];
- WeightedGridGraph.COMPASS_DIRS = [
- new Vector2(1, 0),
- new Vector2(1, -1),
- new Vector2(0, -1),
- new Vector2(-1, -1),
- new Vector2(-1, 0),
- new Vector2(-1, 1),
- new Vector2(0, 1),
- new Vector2(1, 1),
- ];
- return WeightedGridGraph;
-}());
-var WeightedNode = (function (_super) {
- __extends(WeightedNode, _super);
- function WeightedNode(data) {
- var _this = _super.call(this) || this;
- _this.data = data;
- return _this;
- }
- return WeightedNode;
-}(PriorityQueueNode));
-var WeightedPathfinder = (function () {
- function WeightedPathfinder() {
- }
- WeightedPathfinder.search = function (graph, start, goal) {
- var _this = this;
- var foundPath = false;
- var cameFrom = new Map();
- cameFrom.set(start, start);
- var costSoFar = new Map();
- var frontier = new PriorityQueue(1000);
- frontier.enqueue(new WeightedNode(start), 0);
- costSoFar.set(start, 0);
- var _loop_4 = function () {
- var current = frontier.dequeue();
- if (JSON.stringify(current.data) == JSON.stringify(goal)) {
- foundPath = true;
- return "break";
+ PriorityQueue.prototype.cascadeUp = function (node) {
+ var parent = Math.floor(node.queueIndex / 2);
+ while (parent >= 1) {
+ var parentNode = this._nodes[parent];
+ if (this.hasHigherPriority(parentNode, node))
+ break;
+ this.swap(node, parentNode);
+ parent = Math.floor(node.queueIndex / 2);
}
- graph.getNeighbors(current.data).forEach(function (next) {
- var newCost = costSoFar.get(current.data) + graph.cost(current.data, next);
- if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) {
- costSoFar.set(next, newCost);
- var priprity = newCost;
- frontier.enqueue(new WeightedNode(next), priprity);
- cameFrom.set(next, current.data);
- }
- });
};
- while (frontier.count > 0) {
- var state_3 = _loop_4();
- if (state_3 === "break")
- break;
+ PriorityQueue.prototype.swap = function (node1, node2) {
+ this._nodes[node1.queueIndex] = node2;
+ this._nodes[node2.queueIndex] = node1;
+ var temp = node1.queueIndex;
+ node1.queueIndex = node2.queueIndex;
+ node2.queueIndex = temp;
+ };
+ PriorityQueue.prototype.hasHigherPriority = function (higher, lower) {
+ return (higher.priority < lower.priority ||
+ (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex));
+ };
+ return PriorityQueue;
+ }());
+ es.PriorityQueue = PriorityQueue;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var BreadthFirstPathfinder = (function () {
+ function BreadthFirstPathfinder() {
}
- return foundPath ? this.recontructPath(cameFrom, start, goal) : null;
- };
- WeightedPathfinder.hasKey = function (map, compareKey) {
- var iterator = map.keys();
- var r;
- while (r = iterator.next(), !r.done) {
- if (JSON.stringify(r.value) == JSON.stringify(compareKey))
- return true;
- }
- return false;
- };
- WeightedPathfinder.getKey = function (map, compareKey) {
- var iterator = map.keys();
- var valueIterator = map.values();
- var r;
- var v;
- while (r = iterator.next(), v = valueIterator.next(), !r.done) {
- if (JSON.stringify(r.value) == JSON.stringify(compareKey))
- return v.value;
- }
- return null;
- };
- WeightedPathfinder.recontructPath = function (cameFrom, start, goal) {
- var path = [];
- var current = goal;
- path.push(goal);
- while (current != start) {
- current = this.getKey(cameFrom, current);
- path.push(current);
- }
- path.reverse();
- return path;
- };
- return WeightedPathfinder;
-}());
-var DebugDefaults = (function () {
- function DebugDefaults() {
- }
- DebugDefaults.verletParticle = 0xDC345E;
- DebugDefaults.verletConstraintEdge = 0x433E36;
- return DebugDefaults;
-}());
-var Component = (function (_super) {
- __extends(Component, _super);
- function Component() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this._enabled = true;
- _this.updateInterval = 1;
- return _this;
- }
- Object.defineProperty(Component.prototype, "enabled", {
- get: function () {
- return this.entity ? this.entity.enabled && this._enabled : this._enabled;
- },
- set: function (value) {
- this.setEnabled(value);
- },
- enumerable: true,
- configurable: true
- });
- Component.prototype.setEnabled = function (isEnabled) {
- if (this._enabled != isEnabled) {
- this._enabled = isEnabled;
- if (this._enabled) {
- this.onEnabled();
+ BreadthFirstPathfinder.search = function (graph, start, goal) {
+ var _this = this;
+ var foundPath = false;
+ var frontier = [];
+ frontier.unshift(start);
+ var cameFrom = new Map();
+ cameFrom.set(start, start);
+ var _loop_3 = function () {
+ var current = frontier.shift();
+ if (JSON.stringify(current) == JSON.stringify(goal)) {
+ foundPath = true;
+ return "break";
+ }
+ graph.getNeighbors(current).forEach(function (next) {
+ if (!_this.hasKey(cameFrom, next)) {
+ frontier.unshift(next);
+ cameFrom.set(next, current);
+ }
+ });
+ };
+ while (frontier.length > 0) {
+ var state_2 = _loop_3();
+ if (state_2 === "break")
+ break;
}
- else {
- this.onDisabled();
+ return foundPath ? es.AStarPathfinder.recontructPath(cameFrom, start, goal) : null;
+ };
+ BreadthFirstPathfinder.hasKey = function (map, compareKey) {
+ var iterator = map.keys();
+ var r;
+ while (r = iterator.next(), !r.done) {
+ if (JSON.stringify(r.value) == JSON.stringify(compareKey))
+ return true;
}
+ return false;
+ };
+ return BreadthFirstPathfinder;
+ }());
+ es.BreadthFirstPathfinder = BreadthFirstPathfinder;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var UnweightedGraph = (function () {
+ function UnweightedGraph() {
+ this.edges = new Map();
}
- return this;
- };
- Component.prototype.initialize = function () {
- };
- Component.prototype.onAddedToEntity = function () {
- };
- Component.prototype.onRemovedFromEntity = function () {
- };
- Component.prototype.onEnabled = function () {
- };
- Component.prototype.onDisabled = function () {
- };
- Component.prototype.update = function () {
- };
- Component.prototype.debugRender = function () {
- };
- Component.prototype.onEntityTransformChanged = function (comp) {
- };
- Component.prototype.registerComponent = function () {
- this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false);
- this.entity.scene.entityProcessors.onComponentAdded(this.entity);
- };
- Component.prototype.deregisterComponent = function () {
- this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this));
- this.entity.scene.entityProcessors.onComponentRemoved(this.entity);
- };
- return Component;
-}(egret.DisplayObjectContainer));
-var Entity = (function (_super) {
- __extends(Entity, _super);
- function Entity(name) {
- var _this = _super.call(this) || this;
- _this._updateOrder = 0;
- _this._enabled = true;
- _this._tag = 0;
- _this.name = name;
- _this.components = new ComponentList(_this);
- _this.id = Entity._idGenerator++;
- _this.componentBits = new BitSet();
- return _this;
- }
- Object.defineProperty(Entity.prototype, "isDestoryed", {
- get: function () {
- return this._isDestoryed;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Entity.prototype, "position", {
- get: function () {
- return new Vector2(this.x, this.y);
- },
- set: function (value) {
- this.$setX(value.x);
- this.$setY(value.y);
- this.onEntityTransformChanged(TransformComponent.position);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Entity.prototype, "scale", {
- get: function () {
- return new Vector2(this.scaleX, this.scaleY);
- },
- set: function (value) {
- this.$setScaleX(value.x);
- this.$setScaleY(value.y);
- this.onEntityTransformChanged(TransformComponent.scale);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Entity.prototype, "rotation", {
- set: function (value) {
- this.$setRotation(value);
- this.onEntityTransformChanged(TransformComponent.rotation);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Entity.prototype, "enabled", {
- get: function () {
- return this._enabled;
- },
- set: function (value) {
- this.setEnabled(value);
- },
- enumerable: true,
- configurable: true
- });
- Entity.prototype.setEnabled = function (isEnabled) {
- if (this._enabled != isEnabled) {
- this._enabled = isEnabled;
+ UnweightedGraph.prototype.addEdgesForNode = function (node, edges) {
+ this.edges.set(node, edges);
+ return this;
+ };
+ UnweightedGraph.prototype.getNeighbors = function (node) {
+ return this.edges.get(node);
+ };
+ return UnweightedGraph;
+ }());
+ es.UnweightedGraph = UnweightedGraph;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Vector2 = (function () {
+ function Vector2(x, y) {
+ this.x = 0;
+ this.y = 0;
+ this.x = x ? x : 0;
+ this.y = y != undefined ? y : this.x;
}
- return this;
- };
- Object.defineProperty(Entity.prototype, "tag", {
- get: function () {
- return this._tag;
- },
- set: function (value) {
- this.setTag(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Entity.prototype, "stage", {
- get: function () {
- if (!this.scene)
- return null;
- return this.scene.stage;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Entity.prototype, "updateOrder", {
- get: function () {
- return this._updateOrder;
- },
- set: function (value) {
- this.setUpdateOrder(value);
- },
- enumerable: true,
- configurable: true
- });
- Entity.prototype.roundPosition = function () {
- this.position = Vector2Ext.round(this.position);
- };
- Entity.prototype.setUpdateOrder = function (updateOrder) {
- if (this._updateOrder != updateOrder) {
- this._updateOrder = updateOrder;
- if (this.scene) {
+ Object.defineProperty(Vector2, "zero", {
+ get: function () {
+ return Vector2.zeroVector2;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Vector2, "one", {
+ get: function () {
+ return Vector2.unitVector2;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Vector2, "unitX", {
+ get: function () {
+ return Vector2.unitXVector;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Vector2, "unitY", {
+ get: function () {
+ return Vector2.unitYVector;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Vector2.add = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x + value2.x;
+ result.y = value1.y + value2.y;
+ return result;
+ };
+ Vector2.divide = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x / value2.x;
+ result.y = value1.y / value2.y;
+ return result;
+ };
+ Vector2.multiply = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x * value2.x;
+ result.y = value1.y * value2.y;
+ return result;
+ };
+ Vector2.subtract = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x - value2.x;
+ result.y = value1.y - value2.y;
+ return result;
+ };
+ Vector2.normalize = function (value) {
+ var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y));
+ value.x *= val;
+ value.y *= val;
+ return value;
+ };
+ Vector2.dot = function (value1, value2) {
+ return (value1.x * value2.x) + (value1.y * value2.y);
+ };
+ Vector2.distanceSquared = function (value1, value2) {
+ var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
+ return (v1 * v1) + (v2 * v2);
+ };
+ Vector2.clamp = function (value1, min, max) {
+ return new Vector2(es.MathHelper.clamp(value1.x, min.x, max.x), es.MathHelper.clamp(value1.y, min.y, max.y));
+ };
+ Vector2.lerp = function (value1, value2, amount) {
+ return new Vector2(es.MathHelper.lerp(value1.x, value2.x, amount), es.MathHelper.lerp(value1.y, value2.y, amount));
+ };
+ Vector2.transform = function (position, matrix) {
+ return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31, (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32);
+ };
+ Vector2.distance = function (value1, value2) {
+ var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
+ return Math.sqrt((v1 * v1) + (v2 * v2));
+ };
+ Vector2.negate = function (value) {
+ var result = new Vector2();
+ result.x = -value.x;
+ result.y = -value.y;
+ return result;
+ };
+ Vector2.prototype.add = function (value) {
+ this.x += value.x;
+ this.y += value.y;
+ return this;
+ };
+ Vector2.prototype.divide = function (value) {
+ this.x /= value.x;
+ this.y /= value.y;
+ return this;
+ };
+ Vector2.prototype.multiply = function (value) {
+ this.x *= value.x;
+ this.y *= value.y;
+ return this;
+ };
+ Vector2.prototype.subtract = function (value) {
+ this.x -= value.x;
+ this.y -= value.y;
+ return this;
+ };
+ Vector2.prototype.normalize = function () {
+ var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y));
+ this.x *= val;
+ this.y *= val;
+ return this;
+ };
+ Vector2.prototype.length = function () {
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
+ };
+ Vector2.prototype.lengthSquared = function () {
+ return (this.x * this.x) + (this.y * this.y);
+ };
+ Vector2.prototype.round = function () {
+ return new Vector2(Math.round(this.x), Math.round(this.y));
+ };
+ Vector2.prototype.equals = function (other) {
+ return other.x == this.x && other.y == this.y;
+ };
+ Vector2.unitYVector = new Vector2(0, 1);
+ Vector2.unitXVector = new Vector2(1, 0);
+ Vector2.unitVector2 = new Vector2(1, 1);
+ Vector2.zeroVector2 = new Vector2(0, 0);
+ return Vector2;
+ }());
+ es.Vector2 = Vector2;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var UnweightedGridGraph = (function () {
+ function UnweightedGridGraph(width, height, allowDiagonalSearch) {
+ if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; }
+ this.walls = [];
+ this._neighbors = new Array(4);
+ this._width = width;
+ this._hegiht = height;
+ this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS;
+ }
+ UnweightedGridGraph.prototype.isNodeInBounds = function (node) {
+ return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht;
+ };
+ UnweightedGridGraph.prototype.isNodePassable = function (node) {
+ return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); });
+ };
+ UnweightedGridGraph.prototype.getNeighbors = function (node) {
+ var _this = this;
+ this._neighbors.length = 0;
+ this._dirs.forEach(function (dir) {
+ var next = new es.Vector2(node.x + dir.x, node.y + dir.y);
+ if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
+ _this._neighbors.push(next);
+ });
+ return this._neighbors;
+ };
+ UnweightedGridGraph.prototype.search = function (start, goal) {
+ return es.BreadthFirstPathfinder.search(this, start, goal);
+ };
+ UnweightedGridGraph.CARDINAL_DIRS = [
+ new es.Vector2(1, 0),
+ new es.Vector2(0, -1),
+ new es.Vector2(-1, 0),
+ new es.Vector2(0, -1)
+ ];
+ UnweightedGridGraph.COMPASS_DIRS = [
+ new es.Vector2(1, 0),
+ new es.Vector2(1, -1),
+ new es.Vector2(0, -1),
+ new es.Vector2(-1, -1),
+ new es.Vector2(-1, 0),
+ new es.Vector2(-1, 1),
+ new es.Vector2(0, 1),
+ new es.Vector2(1, 1),
+ ];
+ return UnweightedGridGraph;
+ }());
+ es.UnweightedGridGraph = UnweightedGridGraph;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var WeightedGridGraph = (function () {
+ function WeightedGridGraph(width, height, allowDiagonalSearch) {
+ if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; }
+ this.walls = [];
+ this.weightedNodes = [];
+ this.defaultWeight = 1;
+ this.weightedNodeWeight = 5;
+ this._neighbors = new Array(4);
+ this._width = width;
+ this._height = height;
+ this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS;
+ }
+ WeightedGridGraph.prototype.isNodeInBounds = function (node) {
+ return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
+ };
+ WeightedGridGraph.prototype.isNodePassable = function (node) {
+ return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); });
+ };
+ WeightedGridGraph.prototype.search = function (start, goal) {
+ return es.WeightedPathfinder.search(this, start, goal);
+ };
+ WeightedGridGraph.prototype.getNeighbors = function (node) {
+ var _this = this;
+ this._neighbors.length = 0;
+ this._dirs.forEach(function (dir) {
+ var next = new es.Vector2(node.x + dir.x, node.y + dir.y);
+ if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
+ _this._neighbors.push(next);
+ });
+ return this._neighbors;
+ };
+ WeightedGridGraph.prototype.cost = function (from, to) {
+ return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight;
+ };
+ WeightedGridGraph.CARDINAL_DIRS = [
+ new es.Vector2(1, 0),
+ new es.Vector2(0, -1),
+ new es.Vector2(-1, 0),
+ new es.Vector2(0, 1)
+ ];
+ WeightedGridGraph.COMPASS_DIRS = [
+ new es.Vector2(1, 0),
+ new es.Vector2(1, -1),
+ new es.Vector2(0, -1),
+ new es.Vector2(-1, -1),
+ new es.Vector2(-1, 0),
+ new es.Vector2(-1, 1),
+ new es.Vector2(0, 1),
+ new es.Vector2(1, 1),
+ ];
+ return WeightedGridGraph;
+ }());
+ es.WeightedGridGraph = WeightedGridGraph;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var WeightedNode = (function (_super) {
+ __extends(WeightedNode, _super);
+ function WeightedNode(data) {
+ var _this = _super.call(this) || this;
+ _this.data = data;
+ return _this;
+ }
+ return WeightedNode;
+ }(es.PriorityQueueNode));
+ es.WeightedNode = WeightedNode;
+ var WeightedPathfinder = (function () {
+ function WeightedPathfinder() {
+ }
+ WeightedPathfinder.search = function (graph, start, goal) {
+ var _this = this;
+ var foundPath = false;
+ var cameFrom = new Map();
+ cameFrom.set(start, start);
+ var costSoFar = new Map();
+ var frontier = new es.PriorityQueue(1000);
+ frontier.enqueue(new WeightedNode(start), 0);
+ costSoFar.set(start, 0);
+ var _loop_4 = function () {
+ var current = frontier.dequeue();
+ if (JSON.stringify(current.data) == JSON.stringify(goal)) {
+ foundPath = true;
+ return "break";
+ }
+ graph.getNeighbors(current.data).forEach(function (next) {
+ var newCost = costSoFar.get(current.data) + graph.cost(current.data, next);
+ if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) {
+ costSoFar.set(next, newCost);
+ var priprity = newCost;
+ frontier.enqueue(new WeightedNode(next), priprity);
+ cameFrom.set(next, current.data);
+ }
+ });
+ };
+ while (frontier.count > 0) {
+ var state_3 = _loop_4();
+ if (state_3 === "break")
+ break;
+ }
+ return foundPath ? this.recontructPath(cameFrom, start, goal) : null;
+ };
+ WeightedPathfinder.recontructPath = function (cameFrom, start, goal) {
+ var path = [];
+ var current = goal;
+ path.push(goal);
+ while (current != start) {
+ current = this.getKey(cameFrom, current);
+ path.push(current);
+ }
+ path.reverse();
+ return path;
+ };
+ WeightedPathfinder.hasKey = function (map, compareKey) {
+ var iterator = map.keys();
+ var r;
+ while (r = iterator.next(), !r.done) {
+ if (JSON.stringify(r.value) == JSON.stringify(compareKey))
+ return true;
+ }
+ return false;
+ };
+ WeightedPathfinder.getKey = function (map, compareKey) {
+ var iterator = map.keys();
+ var valueIterator = map.values();
+ var r;
+ var v;
+ while (r = iterator.next(), v = valueIterator.next(), !r.done) {
+ if (JSON.stringify(r.value) == JSON.stringify(compareKey))
+ return v.value;
+ }
+ return null;
+ };
+ return WeightedPathfinder;
+ }());
+ es.WeightedPathfinder = WeightedPathfinder;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Debug = (function () {
+ function Debug() {
+ }
+ Debug.drawHollowRect = function (rectanle, color, duration) {
+ if (duration === void 0) { duration = 0; }
+ this._debugDrawItems.push(new es.DebugDrawItem(rectanle, color, duration));
+ };
+ Debug.render = function () {
+ if (this._debugDrawItems.length > 0) {
+ var debugShape = new egret.Shape();
+ if (es.Core.scene) {
+ es.Core.scene.addChild(debugShape);
+ }
+ for (var i = this._debugDrawItems.length - 1; i >= 0; i--) {
+ var item = this._debugDrawItems[i];
+ if (item.draw(debugShape))
+ this._debugDrawItems.removeAt(i);
+ }
+ }
+ };
+ Debug._debugDrawItems = [];
+ return Debug;
+ }());
+ es.Debug = Debug;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var DebugDefaults = (function () {
+ function DebugDefaults() {
+ }
+ DebugDefaults.verletParticle = 0xDC345E;
+ DebugDefaults.verletConstraintEdge = 0x433E36;
+ return DebugDefaults;
+ }());
+ es.DebugDefaults = DebugDefaults;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var DebugDrawType;
+ (function (DebugDrawType) {
+ DebugDrawType[DebugDrawType["line"] = 0] = "line";
+ DebugDrawType[DebugDrawType["hollowRectangle"] = 1] = "hollowRectangle";
+ DebugDrawType[DebugDrawType["pixel"] = 2] = "pixel";
+ DebugDrawType[DebugDrawType["text"] = 3] = "text";
+ })(DebugDrawType = es.DebugDrawType || (es.DebugDrawType = {}));
+ var DebugDrawItem = (function () {
+ function DebugDrawItem(rectangle, color, duration) {
+ this.rectangle = rectangle;
+ this.color = color;
+ this.duration = duration;
+ this.drawType = DebugDrawType.hollowRectangle;
+ }
+ DebugDrawItem.prototype.draw = function (shape) {
+ switch (this.drawType) {
+ case DebugDrawType.line:
+ es.DrawUtils.drawLine(shape, this.start, this.end, this.color);
+ break;
+ case DebugDrawType.hollowRectangle:
+ es.DrawUtils.drawHollowRect(shape, this.rectangle, this.color);
+ break;
+ case DebugDrawType.pixel:
+ es.DrawUtils.drawPixel(shape, new es.Vector2(this.x, this.y), this.color, this.size);
+ break;
+ case DebugDrawType.text:
+ break;
+ }
+ this.duration -= es.Time.deltaTime;
+ return this.duration < 0;
+ };
+ return DebugDrawItem;
+ }());
+ es.DebugDrawItem = DebugDrawItem;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Component = (function (_super) {
+ __extends(Component, _super);
+ function Component() {
+ var _this = _super !== null && _super.apply(this, arguments) || this;
+ _this.updateInterval = 1;
+ _this._enabled = true;
+ _this._updateOrder = 0;
+ return _this;
+ }
+ Object.defineProperty(Component.prototype, "transform", {
+ get: function () {
+ return this.entity.transform;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Component.prototype, "enabled", {
+ get: function () {
+ return this.entity ? this.entity.enabled && this._enabled : this._enabled;
+ },
+ set: function (value) {
+ this.setEnabled(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Component.prototype, "updateOrder", {
+ get: function () {
+ return this._updateOrder;
+ },
+ set: function (value) {
+ this.setUpdateOrder(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Component.prototype.initialize = function () {
+ };
+ Component.prototype.onAddedToEntity = function () {
+ };
+ Component.prototype.onRemovedFromEntity = function () {
+ };
+ Component.prototype.onEntityTransformChanged = function (comp) {
+ };
+ Component.prototype.debugRender = function () {
+ };
+ Component.prototype.onEnabled = function () {
+ };
+ Component.prototype.onDisabled = function () {
+ };
+ Component.prototype.update = function () {
+ };
+ Component.prototype.setEnabled = function (isEnabled) {
+ if (this._enabled != isEnabled) {
+ this._enabled = isEnabled;
+ if (this._enabled) {
+ this.onEnabled();
+ }
+ else {
+ this.onDisabled();
+ }
}
return this;
- }
- };
- Entity.prototype.setTag = function (tag) {
- if (this._tag != tag) {
- if (this.scene) {
- this.scene.entities.removeFromTagList(this);
- }
- this._tag = tag;
- if (this.scene) {
- this.scene.entities.addToTagList(this);
+ };
+ Component.prototype.setUpdateOrder = function (updateOrder) {
+ if (this._updateOrder != updateOrder) {
+ this._updateOrder = updateOrder;
}
+ return this;
+ };
+ Component.prototype.clone = function () {
+ var component = ObjectUtils.clone(this);
+ component.entity = null;
+ return component;
+ };
+ return Component;
+ }(egret.HashObject));
+ es.Component = Component;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Core = (function (_super) {
+ __extends(Core, _super);
+ function Core() {
+ var _this = _super.call(this) || this;
+ _this._globalManagers = [];
+ Core._instance = _this;
+ Core.emitter = new es.Emitter();
+ Core.content = new es.ContentManager();
+ _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
+ return _this;
}
- return this;
- };
- Entity.prototype.attachToScene = function (newScene) {
- this.scene = newScene;
- newScene.entities.add(this);
- this.components.registerAllComponents();
- for (var i = 0; i < this.numChildren; i++) {
- this.getChildAt(i).entity.attachToScene(newScene);
- }
- };
- Entity.prototype.detachFromScene = function () {
- this.scene.entities.remove(this);
- this.components.deregisterAllComponents();
- for (var i = 0; i < this.numChildren; i++)
- this.getChildAt(i).entity.detachFromScene();
- };
- Entity.prototype.addComponent = function (component) {
- component.entity = this;
- this.components.add(component);
- this.addChild(component);
- component.initialize();
- return component;
- };
- Entity.prototype.hasComponent = function (type) {
- return this.components.getComponent(type, false) != null;
- };
- Entity.prototype.getOrCreateComponent = function (type) {
- var comp = this.components.getComponent(type, true);
- if (!comp) {
- comp = this.addComponent(type);
- }
- return comp;
- };
- Entity.prototype.getComponent = function (type) {
- return this.components.getComponent(type, false);
- };
- Entity.prototype.getComponents = function (typeName, componentList) {
- return this.components.getComponents(typeName, componentList);
- };
- Entity.prototype.onEntityTransformChanged = function (comp) {
- this.components.onEntityTransformChanged(comp);
- };
- Entity.prototype.removeComponentForType = function (type) {
- var comp = this.getComponent(type);
- if (comp) {
- this.removeComponent(comp);
- return true;
- }
- return false;
- };
- Entity.prototype.removeComponent = function (component) {
- this.components.remove(component);
- };
- Entity.prototype.removeAllComponents = function () {
- for (var i = 0; i < this.components.count; i++) {
- this.removeComponent(this.components.buffer[i]);
- }
- };
- Entity.prototype.update = function () {
- this.components.update();
- };
- Entity.prototype.onAddedToScene = function () {
- };
- Entity.prototype.onRemovedFromScene = function () {
- if (this._isDestoryed)
- this.components.removeAllComponents();
- };
- Entity.prototype.destroy = function () {
- this._isDestoryed = true;
- this.scene.entities.remove(this);
- this.removeChildren();
- for (var i = this.numChildren - 1; i >= 0; i--) {
- var child = this.getChildAt(i);
- child.entity.destroy();
- }
- };
- return Entity;
-}(egret.DisplayObjectContainer));
-var TransformComponent;
-(function (TransformComponent) {
- TransformComponent[TransformComponent["rotation"] = 0] = "rotation";
- TransformComponent[TransformComponent["scale"] = 1] = "scale";
- TransformComponent[TransformComponent["position"] = 2] = "position";
-})(TransformComponent || (TransformComponent = {}));
-var Scene = (function (_super) {
- __extends(Scene, _super);
- function Scene() {
- var _this = _super.call(this) || this;
- _this.enablePostProcessing = true;
- _this._renderers = [];
- _this._postProcessors = [];
- _this.entityProcessors = new EntityProcessorList();
- _this.renderableComponents = new RenderableComponentList();
- _this.entities = new EntityList(_this);
- _this.content = new ContentManager();
- _this.width = SceneManager.stage.stageWidth;
- _this.height = SceneManager.stage.stageHeight;
- _this.addEventListener(egret.Event.ACTIVATE, _this.onActive, _this);
- _this.addEventListener(egret.Event.DEACTIVATE, _this.onDeactive, _this);
- return _this;
- }
- Scene.prototype.createEntity = function (name) {
- var entity = new Entity(name);
- entity.position = new Vector2(0, 0);
- return this.addEntity(entity);
- };
- Scene.prototype.addEntity = function (entity) {
- this.entities.add(entity);
- entity.scene = this;
- this.addChild(entity);
- for (var i = 0; i < entity.numChildren; i++)
- this.addEntity(entity.getChildAt(i).entity);
- return entity;
- };
- Scene.prototype.destroyAllEntities = function () {
- for (var i = 0; i < this.entities.count; i++) {
- this.entities.buffer[i].destroy();
- }
- };
- Scene.prototype.findEntity = function (name) {
- return this.entities.findEntity(name);
- };
- Scene.prototype.addEntityProcessor = function (processor) {
- processor.scene = this;
- this.entityProcessors.add(processor);
- return processor;
- };
- Scene.prototype.removeEntityProcessor = function (processor) {
- this.entityProcessors.remove(processor);
- };
- Scene.prototype.getEntityProcessor = function () {
- return this.entityProcessors.getProcessor();
- };
- Scene.prototype.addRenderer = function (renderer) {
- this._renderers.push(renderer);
- this._renderers.sort();
- renderer.onAddedToScene(this);
- return renderer;
- };
- Scene.prototype.getRenderer = function (type) {
- for (var i = 0; i < this._renderers.length; i++) {
- if (this._renderers[i] instanceof type)
- return this._renderers[i];
- }
- return null;
- };
- Scene.prototype.removeRenderer = function (renderer) {
- this._renderers.remove(renderer);
- renderer.unload();
- };
- Scene.prototype.begin = function () {
- if (SceneManager.sceneTransition) {
- SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1);
- }
- else {
- SceneManager.stage.addChild(this);
- }
- if (this._renderers.length == 0) {
- this.addRenderer(new DefaultRenderer());
- console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
- }
- this.camera = this.createEntity("camera").getOrCreateComponent(new Camera());
- Physics.reset();
- if (this.entityProcessors)
- this.entityProcessors.begin();
- this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight);
- this._didSceneBegin = true;
- this.onStart();
- };
- Scene.prototype.end = function () {
- this._didSceneBegin = false;
- this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
- this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
- for (var i = 0; i < this._renderers.length; i++) {
- this._renderers[i].unload();
- }
- for (var i = 0; i < this._postProcessors.length; i++) {
- this._postProcessors[i].unload();
- }
- this.entities.removeAllEntities();
- this.removeChildren();
- Physics.clear();
- this.camera = null;
- this.content.dispose();
- if (this.entityProcessors)
- this.entityProcessors.end();
- this.unload();
- if (this.parent)
- this.parent.removeChild(this);
- };
- Scene.prototype.onStart = function () {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- return [2];
- });
+ Object.defineProperty(Core, "Instance", {
+ get: function () {
+ return this._instance;
+ },
+ enumerable: true,
+ configurable: true
});
- };
- Scene.prototype.onActive = function () {
- };
- Scene.prototype.onDeactive = function () {
- };
- Scene.prototype.unload = function () { };
- Scene.prototype.update = function () {
- this.entities.updateLists();
- if (this.entityProcessors)
- this.entityProcessors.update();
- this.entities.update();
- if (this.entityProcessors)
- this.entityProcessors.lateUpdate();
- this.renderableComponents.updateList();
- };
- Scene.prototype.postRender = function () {
- var enabledCounter = 0;
- if (this.enablePostProcessing) {
- for (var i = 0; i < this._postProcessors.length; i++) {
- if (this._postProcessors[i].enable) {
- var isEven = MathHelper.isEven(enabledCounter);
- enabledCounter++;
- this._postProcessors[i].process();
- }
- }
- }
- };
- Scene.prototype.render = function () {
- for (var i = 0; i < this._renderers.length; i++) {
- this._renderers[i].render(this);
- }
- };
- Scene.prototype.addPostProcessor = function (postProcessor) {
- this._postProcessors.push(postProcessor);
- this._postProcessors.sort();
- postProcessor.onAddedToScene(this);
- if (this._didSceneBegin) {
- postProcessor.onSceneBackBufferSizeChanged(this.stage.stageWidth, this.stage.stageHeight);
- }
- return postProcessor;
- };
- return Scene;
-}(egret.DisplayObjectContainer));
-var SceneManager = (function () {
- function SceneManager(stage) {
- stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this);
- SceneManager.stage = stage;
- SceneManager.initialize(stage);
- }
- Object.defineProperty(SceneManager, "scene", {
- get: function () {
- return this._scene;
- },
- set: function (value) {
- if (!value)
- throw new Error("场景不能为空");
- if (this._scene == null) {
- this._scene = value;
- this._scene.begin();
- }
- else {
- this._nextScene = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- SceneManager.initialize = function (stage) {
- Input.initialize(stage);
- };
- SceneManager.update = function () {
- Time.update(egret.getTimer());
- if (SceneManager._scene) {
- for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) {
- if (GlobalManager.globalManagers[i].enabled)
- GlobalManager.globalManagers[i].update();
- }
- if (!SceneManager.sceneTransition ||
- (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) {
- SceneManager._scene.update();
- }
- if (SceneManager._nextScene) {
- SceneManager._scene.end();
- for (var i = 0; i < SceneManager._scene.entities.buffer.length; i++) {
- var entity = SceneManager._scene.entities.buffer[i];
- entity.destroy();
- }
- SceneManager._scene = SceneManager._nextScene;
- SceneManager._nextScene = null;
- SceneManager._scene.begin();
- }
- }
- SceneManager.render();
- };
- SceneManager.render = function () {
- if (this.sceneTransition) {
- this.sceneTransition.preRender();
- if (this._scene && !this.sceneTransition.hasPreviousSceneRender) {
- this._scene.render();
- this._scene.postRender();
- this.sceneTransition.onBeginTransition();
- }
- else if (this.sceneTransition) {
- if (this._scene && this.sceneTransition.isNewSceneLoaded) {
- this._scene.render();
- this._scene.postRender();
- }
- this.sceneTransition.render();
- }
- }
- else if (this._scene) {
- this._scene.render();
- this._scene.postRender();
- }
- };
- SceneManager.startSceneTransition = function (sceneTransition) {
- if (this.sceneTransition) {
- console.warn("在前一个场景完成之前,不能开始一个新的场景转换。");
- return;
- }
- this.sceneTransition = sceneTransition;
- return sceneTransition;
- };
- return SceneManager;
-}());
-var Camera = (function (_super) {
- __extends(Camera, _super);
- function Camera() {
- var _this = _super.call(this) || this;
- _this._origin = Vector2.zero;
- _this._minimumZoom = 0.3;
- _this._maximumZoom = 3;
- _this._position = Vector2.zero;
- _this.followLerp = 0.1;
- _this.deadzone = new Rectangle();
- _this.focusOffset = new Vector2();
- _this.mapLockEnabled = false;
- _this.mapSize = new Vector2();
- _this._worldSpaceDeadZone = new Rectangle();
- _this._desiredPositionDelta = new Vector2();
- _this.cameraStyle = CameraStyle.lockOn;
- _this.width = SceneManager.stage.stageWidth;
- _this.height = SceneManager.stage.stageHeight;
- _this.setZoom(0);
- return _this;
- }
- Object.defineProperty(Camera.prototype, "zoom", {
- get: function () {
- if (this._zoom == 0)
- return 1;
- if (this._zoom < 1)
- return MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0);
- return MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1);
- },
- set: function (value) {
- this.setZoom(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Camera.prototype, "minimumZoom", {
- get: function () {
- return this._minimumZoom;
- },
- set: function (value) {
- this.setMinimumZoom(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Camera.prototype, "maximumZoom", {
- get: function () {
- return this._maximumZoom;
- },
- set: function (value) {
- this.setMaximumZoom(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Camera.prototype, "origin", {
- get: function () {
- return this._origin;
- },
- set: function (value) {
- if (this._origin != value) {
- this._origin = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Camera.prototype, "position", {
- get: function () {
- return this._position;
- },
- set: function (value) {
- this._position = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Camera.prototype, "x", {
- get: function () {
- return this._position.x;
- },
- set: function (value) {
- this._position.x = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Camera.prototype, "y", {
- get: function () {
- return this._position.y;
- },
- set: function (value) {
- this._position.y = value;
- },
- enumerable: true,
- configurable: true
- });
- Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) {
- var oldOrigin = this._origin;
- this.origin = new Vector2(newWidth / 2, newHeight / 2);
- this.entity.position = Vector2.add(this.entity.position, Vector2.subtract(this._origin, oldOrigin));
- };
- Camera.prototype.setMinimumZoom = function (minZoom) {
- if (this._zoom < minZoom)
- this._zoom = this.minimumZoom;
- this._minimumZoom = minZoom;
- return this;
- };
- Camera.prototype.setMaximumZoom = function (maxZoom) {
- if (this._zoom > maxZoom)
- this._zoom = maxZoom;
- this._maximumZoom = maxZoom;
- return this;
- };
- Camera.prototype.setZoom = function (zoom) {
- var newZoom = MathHelper.clamp(zoom, -1, 1);
- if (newZoom == 0) {
- this._zoom = 1;
- }
- else if (newZoom < 0) {
- this._zoom = MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1);
- }
- else {
- this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom);
- }
- SceneManager.scene.scaleX = this._zoom;
- SceneManager.scene.scaleY = this._zoom;
- return this;
- };
- Camera.prototype.setRotation = function (rotation) {
- SceneManager.scene.rotation = rotation;
- return this;
- };
- Camera.prototype.setPosition = function (position) {
- this.entity.position = position;
- return this;
- };
- Camera.prototype.follow = function (targetEntity, cameraStyle) {
- if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; }
- this.targetEntity = targetEntity;
- this.cameraStyle = cameraStyle;
- var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
- switch (this.cameraStyle) {
- case CameraStyle.cameraWindow:
- var w = cameraBounds.width / 6;
- var h = cameraBounds.height / 3;
- this.deadzone = new Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h);
- break;
- case CameraStyle.lockOn:
- this.deadzone = new Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10);
- break;
- }
- };
- Camera.prototype.update = function () {
- var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
- var halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5));
- this._worldSpaceDeadZone.x = this.position.x - halfScreen.x + this.deadzone.x + this.focusOffset.x;
- this._worldSpaceDeadZone.y = this.position.y - halfScreen.y + this.deadzone.y + this.focusOffset.y;
- this._worldSpaceDeadZone.width = this.deadzone.width;
- this._worldSpaceDeadZone.height = this.deadzone.height;
- if (this.targetEntity)
- this.updateFollow();
- this.position = Vector2.lerp(this.position, Vector2.add(this.position, this._desiredPositionDelta), this.followLerp);
- this.entity.roundPosition();
- if (this.mapLockEnabled) {
- this.position = this.clampToMapSize(this.position);
- this.entity.roundPosition();
- }
- };
- Camera.prototype.clampToMapSize = function (position) {
- var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
- var halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5));
- var cameraMax = new Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y);
- return Vector2.clamp(position, halfScreen, cameraMax);
- };
- Camera.prototype.updateFollow = function () {
- this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0;
- if (this.cameraStyle == CameraStyle.lockOn) {
- var targetX = this.targetEntity.position.x;
- var targetY = this.targetEntity.position.y;
- if (this._worldSpaceDeadZone.x > targetX)
- this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
- else if (this._worldSpaceDeadZone.x < targetX)
- this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
- if (this._worldSpaceDeadZone.y < targetY)
- this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
- else if (this._worldSpaceDeadZone.y > targetY)
- this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
- }
- else {
- if (!this._targetCollider) {
- this._targetCollider = this.targetEntity.getComponent(Collider);
- if (!this._targetCollider)
+ Object.defineProperty(Core, "scene", {
+ get: function () {
+ if (!this._instance)
+ return null;
+ return this._instance._scene;
+ },
+ set: function (value) {
+ if (!value) {
+ console.error("场景不能为空");
return;
+ }
+ if (this._instance._scene == null) {
+ this._instance._scene = value;
+ this._instance.addChild(value);
+ this._instance._scene.begin();
+ Core.Instance.onSceneChanged();
+ }
+ else {
+ this._instance._nextScene = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Core.startSceneTransition = function (sceneTransition) {
+ if (this._instance._sceneTransition) {
+ console.warn("在前一个场景完成之前,不能开始一个新的场景转换。");
+ return;
}
- var targetBounds = this.targetEntity.getComponent(Collider).bounds;
- if (!this._worldSpaceDeadZone.containsRect(targetBounds)) {
- if (this._worldSpaceDeadZone.left > targetBounds.left)
- this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left;
- else if (this._worldSpaceDeadZone.right < targetBounds.right)
- this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right;
- if (this._worldSpaceDeadZone.bottom < targetBounds.bottom)
- this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom;
- else if (this._worldSpaceDeadZone.top > targetBounds.top)
- this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top;
+ this._instance._sceneTransition = sceneTransition;
+ return sceneTransition;
+ };
+ Core.registerGlobalManager = function (manager) {
+ this._instance._globalManagers.push(manager);
+ manager.enabled = true;
+ };
+ Core.unregisterGlobalManager = function (manager) {
+ this._instance._globalManagers.remove(manager);
+ manager.enabled = false;
+ };
+ Core.getGlobalManager = function (type) {
+ for (var i = 0; i < this._instance._globalManagers.length; i++) {
+ if (this._instance._globalManagers[i] instanceof type)
+ return this._instance._globalManagers[i];
}
- }
- };
- return Camera;
-}(Component));
-var CameraStyle;
-(function (CameraStyle) {
- CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn";
- CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow";
-})(CameraStyle || (CameraStyle = {}));
-var ComponentPool = (function () {
- function ComponentPool(typeClass) {
- this._type = typeClass;
- this._cache = [];
- }
- ComponentPool.prototype.obtain = function () {
- try {
- return this._cache.length > 0 ? this._cache.shift() : new this._type();
- }
- catch (err) {
- throw new Error(this._type + err);
- }
- };
- ComponentPool.prototype.free = function (component) {
- component.reset();
- this._cache.push(component);
- };
- return ComponentPool;
-}());
-var PooledComponent = (function (_super) {
- __extends(PooledComponent, _super);
- function PooledComponent() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- return PooledComponent;
-}(Component));
-var RenderableComponent = (function (_super) {
- __extends(RenderableComponent, _super);
- function RenderableComponent() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this._areBoundsDirty = true;
- _this._bounds = new Rectangle();
- _this._localOffset = Vector2.zero;
- _this.color = 0x000000;
- return _this;
- }
- Object.defineProperty(RenderableComponent.prototype, "width", {
- get: function () {
- return this.getWidth();
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(RenderableComponent.prototype, "height", {
- get: function () {
- return this.getHeight();
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(RenderableComponent.prototype, "isVisible", {
- get: function () {
- return this._isVisible;
- },
- set: function (value) {
- this._isVisible = value;
- if (this._isVisible)
- this.onBecameVisible();
- else
- this.onBecameInvisible();
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(RenderableComponent.prototype, "bounds", {
- get: function () {
- return new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height);
- },
- enumerable: true,
- configurable: true
- });
- RenderableComponent.prototype.getWidth = function () {
- return this.bounds.width;
- };
- RenderableComponent.prototype.getHeight = function () {
- return this.bounds.height;
- };
- RenderableComponent.prototype.onBecameVisible = function () { };
- RenderableComponent.prototype.onBecameInvisible = function () { };
- RenderableComponent.prototype.isVisibleFromCamera = function (camera) {
- this.isVisible = camera.getBounds().intersects(this.getBounds());
- return this.isVisible;
- };
- return RenderableComponent;
-}(PooledComponent));
-var Mesh = (function (_super) {
- __extends(Mesh, _super);
- function Mesh() {
- var _this = _super.call(this) || this;
- _this._mesh = new egret.Mesh();
- return _this;
- }
- Mesh.prototype.setTexture = function (texture) {
- this._mesh.texture = texture;
- return this;
- };
- Mesh.prototype.onAddedToEntity = function () {
- this.addChild(this._mesh);
- };
- Mesh.prototype.onRemovedFromEntity = function () {
- this.removeChild(this._mesh);
- };
- Mesh.prototype.render = function (camera) {
- this.x = this.entity.position.x - camera.position.x + camera.origin.x;
- this.y = this.entity.position.y - camera.position.y + camera.origin.y;
- };
- Mesh.prototype.reset = function () {
- };
- return Mesh;
-}(RenderableComponent));
-var SpriteRenderer = (function (_super) {
- __extends(SpriteRenderer, _super);
- function SpriteRenderer() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Object.defineProperty(SpriteRenderer.prototype, "sprite", {
- get: function () {
- return this._sprite;
- },
- set: function (value) {
- this.setSprite(value);
- },
- enumerable: true,
- configurable: true
- });
- SpriteRenderer.prototype.setSprite = function (sprite) {
- this.removeChildren();
- this._sprite = sprite;
- if (this._sprite) {
- this.anchorOffsetX = this._sprite.origin.x / this._sprite.sourceRect.width;
- this.anchorOffsetY = this._sprite.origin.y / this._sprite.sourceRect.height;
- }
- this.bitmap = new egret.Bitmap(sprite.texture2D);
- this.addChild(this.bitmap);
- return this;
- };
- SpriteRenderer.prototype.setColor = function (color) {
- var colorMatrix = [
- 1, 0, 0, 0, 0,
- 0, 1, 0, 0, 0,
- 0, 0, 1, 0, 0,
- 0, 0, 0, 1, 0
- ];
- colorMatrix[0] = Math.floor(color / 256 / 256) / 255;
- colorMatrix[6] = Math.floor(color / 256 % 256) / 255;
- colorMatrix[12] = color % 256 / 255;
- var colorFilter = new egret.ColorMatrixFilter(colorMatrix);
- this.filters = [colorFilter];
- return this;
- };
- SpriteRenderer.prototype.isVisibleFromCamera = function (camera) {
- this.isVisible = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds);
- this.visible = this.isVisible;
- return this.isVisible;
- };
- SpriteRenderer.prototype.render = function (camera) {
- this.x = -camera.position.x + camera.origin.x;
- this.y = -camera.position.y + camera.origin.y;
- };
- SpriteRenderer.prototype.onRemovedFromEntity = function () {
- if (this.parent)
- this.parent.removeChild(this);
- };
- SpriteRenderer.prototype.reset = function () {
- };
- return SpriteRenderer;
-}(RenderableComponent));
-var TiledSpriteRenderer = (function (_super) {
- __extends(TiledSpriteRenderer, _super);
- function TiledSpriteRenderer(sprite) {
- var _this = _super.call(this) || this;
- _this.leftTexture = new egret.Bitmap();
- _this.rightTexture = new egret.Bitmap();
- _this.leftTexture.texture = sprite.texture2D;
- _this.rightTexture.texture = sprite.texture2D;
- _this.setSprite(sprite);
- _this.sourceRect = sprite.sourceRect;
- return _this;
- }
- Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", {
- get: function () {
- return this.sourceRect.x;
- },
- set: function (value) {
- this.sourceRect.x = value;
- if (this.sourceRect.x < -this.sourceRect.width)
- this.sourceRect.x = this.sourceRect.width;
- else if (this.sourceRect.x > this.sourceRect.width)
- this.sourceRect.x = -this.sourceRect.width;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", {
- get: function () {
- return this.sourceRect.y;
- },
- set: function (value) {
- this.sourceRect.y = value;
- if (this.sourceRect.y < -this.sourceRect.height)
- this.sourceRect.y = this.sourceRect.height;
- else if (this.sourceRect.y > this.sourceRect.height)
- this.sourceRect.y = -this.sourceRect.height;
- },
- enumerable: true,
- configurable: true
- });
- TiledSpriteRenderer.prototype.render = function (camera) {
- if (!this.sprite)
- return;
- _super.prototype.render.call(this, camera);
- var renderTexture = new egret.RenderTexture();
- var cacheBitmap = new egret.DisplayObjectContainer();
- cacheBitmap.removeChildren();
- cacheBitmap.addChild(this.leftTexture);
- cacheBitmap.addChild(this.rightTexture);
- this.leftTexture.x = this.sourceRect.x;
- this.rightTexture.x = this.sourceRect.x + this.sourceRect.width;
- this.leftTexture.y = this.sourceRect.y;
- this.rightTexture.y = this.sourceRect.y;
- cacheBitmap.cacheAsBitmap = true;
- renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
- this.bitmap.texture = renderTexture;
- };
- return TiledSpriteRenderer;
-}(SpriteRenderer));
-var ScrollingSpriteRenderer = (function (_super) {
- __extends(ScrollingSpriteRenderer, _super);
- function ScrollingSpriteRenderer() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.scrollSpeedX = 15;
- _this.scroolSpeedY = 0;
- _this._scrollX = 0;
- _this._scrollY = 0;
- return _this;
- }
- ScrollingSpriteRenderer.prototype.update = function () {
- this.scrollX += this.scrollSpeedX * Time.deltaTime;
- this.scrollY += this.scroolSpeedY * Time.deltaTime;
- this.sourceRect.x = this._scrollX;
- this.sourceRect.y = this._scrollY;
- };
- return ScrollingSpriteRenderer;
-}(TiledSpriteRenderer));
-var Sprite = (function () {
- function Sprite(texture, sourceRect, origin) {
- if (sourceRect === void 0) { sourceRect = new Rectangle(0, 0, texture.textureWidth, texture.textureHeight); }
- if (origin === void 0) { origin = sourceRect.getHalfSize(); }
- this.uvs = new Rectangle();
- this.texture2D = texture;
- this.sourceRect = sourceRect;
- this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5);
- this.origin = origin;
- var inverseTexW = 1 / texture.textureWidth;
- var inverseTexH = 1 / texture.textureHeight;
- this.uvs.x = sourceRect.x * inverseTexW;
- this.uvs.y = sourceRect.y * inverseTexH;
- this.uvs.width = sourceRect.width * inverseTexW;
- this.uvs.height = sourceRect.height * inverseTexH;
- }
- return Sprite;
-}());
-var SpriteAnimation = (function () {
- function SpriteAnimation(sprites, frameRate) {
- this.sprites = sprites;
- this.frameRate = frameRate;
- }
- return SpriteAnimation;
-}());
-var SpriteAnimator = (function (_super) {
- __extends(SpriteAnimator, _super);
- function SpriteAnimator(sprite) {
- var _this = _super.call(this) || this;
- _this.speed = 1;
- _this.animationState = State.none;
- _this._animations = new Map();
- _this._elapsedTime = 0;
- if (sprite)
- _this.setSprite(sprite);
- return _this;
- }
- Object.defineProperty(SpriteAnimator.prototype, "isRunning", {
- get: function () {
- return this.animationState == State.running;
- },
- enumerable: true,
- configurable: true
- });
- SpriteAnimator.prototype.addAnimation = function (name, animation) {
- if (!this.sprite && animation.sprites.length > 0)
- this.setSprite(animation.sprites[0]);
- this._animations[name] = animation;
- return this;
- };
- SpriteAnimator.prototype.play = function (name, loopMode) {
- if (loopMode === void 0) { loopMode = null; }
- this.currentAnimation = this._animations[name];
- this.currentAnimationName = name;
- this.currentFrame = 0;
- this.animationState = State.running;
- this.sprite = this.currentAnimation.sprites[0];
- this._elapsedTime = 0;
- this._loopMode = loopMode ? loopMode : LoopMode.loop;
- };
- SpriteAnimator.prototype.isAnimationActive = function (name) {
- return this.currentAnimation && this.currentAnimationName == name;
- };
- SpriteAnimator.prototype.pause = function () {
- this.animationState = State.paused;
- };
- SpriteAnimator.prototype.unPause = function () {
- this.animationState = State.running;
- };
- SpriteAnimator.prototype.stop = function () {
- this.currentAnimation = null;
- this.currentAnimationName = null;
- this.currentFrame = 0;
- this.animationState = State.none;
- };
- SpriteAnimator.prototype.update = function () {
- if (this.animationState != State.running || !this.currentAnimation)
- return;
- var animation = this.currentAnimation;
- var secondsPerFrame = 1 / (animation.frameRate * this.speed);
- var iterationDuration = secondsPerFrame * animation.sprites.length;
- this._elapsedTime += Time.deltaTime;
- var time = Math.abs(this._elapsedTime);
- if (this._loopMode == LoopMode.once && time > iterationDuration ||
- this._loopMode == LoopMode.pingPongOnce && time > iterationDuration * 2) {
- this.animationState = State.completed;
- this._elapsedTime = 0;
- this.currentFrame = 0;
- this.sprite = animation.sprites[this.currentFrame];
- return;
- }
- var i = Math.floor(time / secondsPerFrame);
- var n = animation.sprites.length;
- if (n > 2 && (this._loopMode == LoopMode.pingPong || this._loopMode == LoopMode.pingPongOnce)) {
- var maxIndex = n - 1;
- this.currentFrame = maxIndex - Math.abs(maxIndex - i % (maxIndex * 2));
- }
- else {
- this.currentFrame = i % n;
- }
- this.sprite = animation.sprites[this.currentFrame];
- };
- return SpriteAnimator;
-}(SpriteRenderer));
-var LoopMode;
-(function (LoopMode) {
- LoopMode[LoopMode["loop"] = 0] = "loop";
- LoopMode[LoopMode["once"] = 1] = "once";
- LoopMode[LoopMode["clampForever"] = 2] = "clampForever";
- LoopMode[LoopMode["pingPong"] = 3] = "pingPong";
- LoopMode[LoopMode["pingPongOnce"] = 4] = "pingPongOnce";
-})(LoopMode || (LoopMode = {}));
-var State;
-(function (State) {
- State[State["none"] = 0] = "none";
- State[State["running"] = 1] = "running";
- State[State["paused"] = 2] = "paused";
- State[State["completed"] = 3] = "completed";
-})(State || (State = {}));
-var Mover = (function (_super) {
- __extends(Mover, _super);
- function Mover() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Mover.prototype.onAddedToEntity = function () {
- this._triggerHelper = new ColliderTriggerHelper(this.entity);
- };
- Mover.prototype.calculateMovement = function (motion) {
- var collisionResult = new CollisionResult();
- if (!this.entity.getComponent(Collider) || !this._triggerHelper) {
return null;
+ };
+ Core.prototype.onOrientationChanged = function () {
+ Core.emitter.emit(es.CoreEvents.OrientationChanged);
+ };
+ Core.prototype.draw = function () {
+ return __awaiter(this, void 0, void 0, function () {
+ return __generator(this, function (_a) {
+ switch (_a.label) {
+ case 0:
+ if (!this._sceneTransition) return [3, 4];
+ this._sceneTransition.preRender();
+ if (!(this._scene && !this._sceneTransition.hasPreviousSceneRender)) return [3, 2];
+ this._scene.render();
+ this._scene.postRender();
+ return [4, this._sceneTransition.onBeginTransition()];
+ case 1:
+ _a.sent();
+ return [3, 3];
+ case 2:
+ if (this._sceneTransition) {
+ if (this._scene && this._sceneTransition.isNewSceneLoaded) {
+ this._scene.render();
+ this._scene.postRender();
+ }
+ this._sceneTransition.render();
+ }
+ _a.label = 3;
+ case 3: return [3, 5];
+ case 4:
+ if (this._scene) {
+ this._scene.render();
+ es.Debug.render();
+ this._scene.postRender();
+ }
+ _a.label = 5;
+ case 5: return [2];
+ }
+ });
+ });
+ };
+ Core.prototype.startDebugUpdate = function () {
+ es.TimeRuler.Instance.startFrame();
+ es.TimeRuler.Instance.beginMark("update", 0x00FF00);
+ };
+ Core.prototype.endDebugUpdate = function () {
+ es.TimeRuler.Instance.endMark("update");
+ };
+ Core.prototype.onSceneChanged = function () {
+ Core.emitter.emit(es.CoreEvents.SceneChanged);
+ es.Time.sceneChanged();
+ };
+ Core.prototype.onGraphicsDeviceReset = function () {
+ Core.emitter.emit(es.CoreEvents.GraphicsDeviceReset);
+ };
+ Core.prototype.initialize = function () {
+ };
+ Core.prototype.update = function () {
+ return __awaiter(this, void 0, void 0, function () {
+ var i;
+ return __generator(this, function (_a) {
+ switch (_a.label) {
+ case 0:
+ es.Time.update(egret.getTimer());
+ if (!this._scene) return [3, 2];
+ for (i = this._globalManagers.length - 1; i >= 0; i--) {
+ if (this._globalManagers[i].enabled)
+ this._globalManagers[i].update();
+ }
+ if (!this._sceneTransition ||
+ (this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) {
+ this._scene.update();
+ }
+ if (!this._nextScene) return [3, 2];
+ this.removeChild(this._scene);
+ this._scene.end();
+ this._scene = this._nextScene;
+ this._nextScene = null;
+ this.onSceneChanged();
+ this.addChild(this._scene);
+ return [4, this._scene.begin()];
+ case 1:
+ _a.sent();
+ _a.label = 2;
+ case 2: return [4, this.draw()];
+ case 3:
+ _a.sent();
+ return [2];
+ }
+ });
+ });
+ };
+ Core.prototype.onAddToStage = function () {
+ Core.graphicsDevice = new es.GraphicsDevice();
+ this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this);
+ this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this);
+ this.addEventListener(egret.Event.ENTER_FRAME, this.update, this);
+ es.Input.initialize();
+ this.initialize();
+ };
+ return Core;
+ }(egret.DisplayObjectContainer));
+ es.Core = Core;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var CoreEvents;
+ (function (CoreEvents) {
+ CoreEvents[CoreEvents["GraphicsDeviceReset"] = 0] = "GraphicsDeviceReset";
+ CoreEvents[CoreEvents["SceneChanged"] = 1] = "SceneChanged";
+ CoreEvents[CoreEvents["OrientationChanged"] = 2] = "OrientationChanged";
+ })(CoreEvents = es.CoreEvents || (es.CoreEvents = {}));
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Entity = (function () {
+ function Entity(name) {
+ this.updateInterval = 1;
+ this._tag = 0;
+ this._enabled = true;
+ this._updateOrder = 0;
+ this.components = new es.ComponentList(this);
+ this.transform = new es.Transform(this);
+ this.name = name;
+ this.id = Entity._idGenerator++;
+ this.componentBits = new es.BitSet();
}
- var colliders = this.entity.getComponents(Collider);
- for (var i = 0; i < colliders.length; i++) {
- var collider = colliders[i];
- if (collider.isTrigger)
- continue;
- var bounds = collider.bounds;
- bounds.x += motion.x;
- bounds.y += motion.y;
- var boxcastResult = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers);
- bounds = boxcastResult.bounds;
- var neighbors = boxcastResult.tempHashSet;
- for (var j = 0; j < neighbors.length; j++) {
- var neighbor = neighbors[j];
- if (neighbor.isTrigger)
- continue;
- var _internalcollisionResult = collider.collidesWith(neighbor, motion);
- if (_internalcollisionResult) {
- motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector);
- if (_internalcollisionResult.collider) {
- collisionResult = _internalcollisionResult;
+ Object.defineProperty(Entity.prototype, "isDestroyed", {
+ get: function () {
+ return this._isDestroyed;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "tag", {
+ get: function () {
+ return this._tag;
+ },
+ set: function (value) {
+ this.setTag(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "enabled", {
+ get: function () {
+ return this._enabled;
+ },
+ set: function (value) {
+ this.setEnabled(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "updateOrder", {
+ get: function () {
+ return this._updateOrder;
+ },
+ set: function (value) {
+ this.setUpdateOrder(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "parent", {
+ get: function () {
+ return this.transform.parent;
+ },
+ set: function (value) {
+ this.transform.setParent(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "childCount", {
+ get: function () {
+ return this.transform.childCount;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "position", {
+ get: function () {
+ return this.transform.position;
+ },
+ set: function (value) {
+ this.transform.setPosition(value.x, value.y);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "localPosition", {
+ get: function () {
+ return this.transform.localPosition;
+ },
+ set: function (value) {
+ this.transform.setLocalPosition(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "rotation", {
+ get: function () {
+ return this.transform.rotation;
+ },
+ set: function (value) {
+ this.transform.setRotation(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "rotationDegrees", {
+ get: function () {
+ return this.transform.rotationDegrees;
+ },
+ set: function (value) {
+ this.transform.setRotationDegrees(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "localRotation", {
+ get: function () {
+ return this.transform.localRotation;
+ },
+ set: function (value) {
+ this.transform.setLocalRotation(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "localRotationDegrees", {
+ get: function () {
+ return this.transform.localRotationDegrees;
+ },
+ set: function (value) {
+ this.transform.setLocalRotationDegrees(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "scale", {
+ get: function () {
+ return this.transform.scale;
+ },
+ set: function (value) {
+ this.transform.setScale(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "localScale", {
+ get: function () {
+ return this.transform.localScale;
+ },
+ set: function (value) {
+ this.transform.setLocalScale(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "worldInverseTransform", {
+ get: function () {
+ return this.transform.worldInverseTransform;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "localToWorldTransform", {
+ get: function () {
+ return this.transform.localToWorldTransform;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "worldToLocalTransform", {
+ get: function () {
+ return this.transform.worldToLocalTransform;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Entity.prototype.onTransformChanged = function (comp) {
+ this.components.onEntityTransformChanged(comp);
+ };
+ Entity.prototype.setTag = function (tag) {
+ if (this._tag != tag) {
+ if (this.scene)
+ this.scene.entities.removeFromTagList(this);
+ this._tag = tag;
+ if (this.scene)
+ this.scene.entities.addToTagList(this);
+ }
+ return this;
+ };
+ Entity.prototype.setEnabled = function (isEnabled) {
+ if (this._enabled != isEnabled) {
+ this._enabled = isEnabled;
+ if (this._enabled)
+ this.components.onEntityEnabled();
+ else
+ this.components.onEntityDisabled();
+ }
+ return this;
+ };
+ Entity.prototype.setUpdateOrder = function (updateOrder) {
+ if (this._updateOrder != updateOrder) {
+ this._updateOrder = updateOrder;
+ if (this.scene) {
+ this.scene.entities.markEntityListUnsorted();
+ this.scene.entities.markTagUnsorted(this.tag);
+ }
+ return this;
+ }
+ };
+ Entity.prototype.destroy = function () {
+ this._isDestroyed = true;
+ this.scene.entities.remove(this);
+ this.transform.parent = null;
+ for (var i = this.transform.childCount - 1; i >= 0; i--) {
+ var child = this.transform.getChild(i);
+ child.entity.destroy();
+ }
+ };
+ Entity.prototype.detachFromScene = function () {
+ this.scene.entities.remove(this);
+ this.components.deregisterAllComponents();
+ for (var i = 0; i < this.transform.childCount; i++)
+ this.transform.getChild(i).entity.detachFromScene();
+ };
+ Entity.prototype.attachToScene = function (newScene) {
+ this.scene = newScene;
+ newScene.entities.add(this);
+ this.components.registerAllComponents();
+ for (var i = 0; i < this.transform.childCount; i++) {
+ this.transform.getChild(i).entity.attachToScene(newScene);
+ }
+ };
+ Entity.prototype.clone = function (position) {
+ if (position === void 0) { position = new es.Vector2(); }
+ var entity = new Entity(this.name + "(clone)");
+ entity.copyFrom(this);
+ entity.transform.position = position;
+ return entity;
+ };
+ Entity.prototype.onAddedToScene = function () {
+ };
+ Entity.prototype.onRemovedFromScene = function () {
+ if (this._isDestroyed)
+ this.components.removeAllComponents();
+ };
+ Entity.prototype.update = function () {
+ this.components.update();
+ };
+ Entity.prototype.addComponent = function (component) {
+ component.entity = this;
+ this.components.add(component);
+ component.initialize();
+ return component;
+ };
+ Entity.prototype.getComponent = function (type) {
+ return this.components.getComponent(type, false);
+ };
+ Entity.prototype.hasComponent = function (type) {
+ return this.components.getComponent(type, false) != null;
+ };
+ Entity.prototype.getOrCreateComponent = function (type) {
+ var comp = this.components.getComponent(type, true);
+ if (!comp) {
+ comp = this.addComponent(type);
+ }
+ return comp;
+ };
+ Entity.prototype.getComponents = function (typeName, componentList) {
+ return this.components.getComponents(typeName, componentList);
+ };
+ Entity.prototype.removeComponent = function (component) {
+ this.components.remove(component);
+ };
+ Entity.prototype.removeComponentForType = function (type) {
+ var comp = this.getComponent(type);
+ if (comp) {
+ this.removeComponent(comp);
+ return true;
+ }
+ return false;
+ };
+ Entity.prototype.removeAllComponents = function () {
+ for (var i = 0; i < this.components.count; i++) {
+ this.removeComponent(this.components.buffer[i]);
+ }
+ };
+ Entity.prototype.compareTo = function (other) {
+ var compare = this._updateOrder - other._updateOrder;
+ if (compare == 0)
+ compare = this.id - other.id;
+ return compare;
+ };
+ Entity.prototype.toString = function () {
+ return "[Entity: name: " + this.name + ", tag: " + this.tag + ", enabled: " + this.enabled + ", depth: " + this.updateOrder + "]";
+ };
+ Entity.prototype.copyFrom = function (entity) {
+ this.tag = entity.tag;
+ this.updateInterval = entity.updateInterval;
+ this.updateOrder = entity.updateOrder;
+ this.enabled = entity.enabled;
+ this.transform.scale = entity.transform.scale;
+ this.transform.rotation = entity.transform.rotation;
+ for (var i = 0; i < entity.components.count; i++)
+ this.addComponent(entity.components.buffer[i].clone());
+ for (var i = 0; i < entity.components._componentsToAdd.length; i++)
+ this.addComponent(entity.components._componentsToAdd[i].clone());
+ for (var i = 0; i < entity.transform.childCount; i++) {
+ var child = entity.transform.getChild(i).entity;
+ var childClone = child.clone();
+ childClone.transform.copyFrom(child.transform);
+ childClone.transform.parent = this.transform;
+ }
+ };
+ return Entity;
+ }());
+ es.Entity = Entity;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Scene = (function (_super) {
+ __extends(Scene, _super);
+ function Scene() {
+ var _this = _super.call(this) || this;
+ _this.enablePostProcessing = true;
+ _this._renderers = [];
+ _this._postProcessors = [];
+ _this.entities = new es.EntityList(_this);
+ _this.renderableComponents = new es.RenderableComponentList();
+ _this.content = new es.ContentManager();
+ _this.entityProcessors = new es.EntityProcessorList();
+ _this.initialize();
+ return _this;
+ }
+ Scene.createWithDefaultRenderer = function () {
+ var scene = new Scene();
+ scene.addRenderer(new es.DefaultRenderer());
+ return scene;
+ };
+ Scene.prototype.initialize = function () {
+ };
+ Scene.prototype.onStart = function () {
+ return __awaiter(this, void 0, void 0, function () {
+ return __generator(this, function (_a) {
+ return [2];
+ });
+ });
+ };
+ Scene.prototype.unload = function () {
+ };
+ Scene.prototype.onActive = function () {
+ };
+ Scene.prototype.onDeactive = function () {
+ };
+ Scene.prototype.begin = function () {
+ return __awaiter(this, void 0, void 0, function () {
+ return __generator(this, function (_a) {
+ if (this._renderers.length == 0) {
+ this.addRenderer(new es.DefaultRenderer());
+ console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
+ }
+ this.camera = this.createEntity("camera").getOrCreateComponent(new es.Camera());
+ es.Physics.reset();
+ if (this.entityProcessors)
+ this.entityProcessors.begin();
+ this.addEventListener(egret.Event.ACTIVATE, this.onActive, this);
+ this.addEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
+ this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight);
+ this._didSceneBegin = true;
+ this.onStart();
+ return [2];
+ });
+ });
+ };
+ Scene.prototype.end = function () {
+ this._didSceneBegin = false;
+ this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
+ this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
+ for (var i = 0; i < this._renderers.length; i++) {
+ this._renderers[i].unload();
+ }
+ for (var i = 0; i < this._postProcessors.length; i++) {
+ this._postProcessors[i].unload();
+ }
+ this.entities.removeAllEntities();
+ this.removeChildren();
+ this.camera = null;
+ this.content.dispose();
+ if (this.entityProcessors)
+ this.entityProcessors.end();
+ if (this.parent)
+ this.parent.removeChild(this);
+ this.unload();
+ };
+ Scene.prototype.update = function () {
+ this.entities.updateLists();
+ if (this.entityProcessors)
+ this.entityProcessors.update();
+ this.entities.update();
+ if (this.entityProcessors)
+ this.entityProcessors.lateUpdate();
+ this.renderableComponents.updateList();
+ };
+ Scene.prototype.render = function () {
+ if (this._renderers.length == 0) {
+ console.error("there are no renderers in the scene!");
+ return;
+ }
+ for (var i = 0; i < this._renderers.length; i++) {
+ this._renderers[i].render(this);
+ }
+ };
+ Scene.prototype.postRender = function () {
+ if (this.enablePostProcessing) {
+ for (var i = 0; i < this._postProcessors.length; i++) {
+ if (this._postProcessors[i].enabled) {
+ this._postProcessors[i].process();
}
}
}
- }
- ListPool.free(colliders);
- return { collisionResult: collisionResult, motion: motion };
- };
- Mover.prototype.applyMovement = function (motion) {
- this.entity.position = Vector2.add(this.entity.position, motion);
- if (this._triggerHelper)
- this._triggerHelper.update();
- };
- Mover.prototype.move = function (motion) {
- var movementResult = this.calculateMovement(motion);
- var collisionResult = movementResult.collisionResult;
- motion = movementResult.motion;
- this.applyMovement(motion);
- return collisionResult;
- };
- return Mover;
-}(Component));
-var Collider = (function (_super) {
- __extends(Collider, _super);
- function Collider() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.physicsLayer = 1 << 0;
- _this.registeredPhysicsBounds = new Rectangle();
- _this.shouldColliderScaleAndRotateWithTransform = true;
- _this.collidesWithLayers = Physics.allLayers;
- _this._localOffset = new Vector2(0, 0);
- return _this;
- }
- Object.defineProperty(Collider.prototype, "bounds", {
- get: function () {
- var bds = this.entity.getBounds();
- return new Rectangle(bds.x, bds.y, bds.width, bds.height);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Collider.prototype, "localOffset", {
- get: function () {
- return new Vector2(this.x, this.y);
- },
- set: function (value) {
- this.setLocalOffset(value);
- },
- enumerable: true,
- configurable: true
- });
- Collider.prototype.setLocalOffset = function (offset) {
- if (this._localOffset != offset) {
- this.unregisterColliderWithPhysicsSystem();
- this.$setX(offset.x);
- this.$setY(offset.y);
- this._localOffsetLength = this._localOffset.length();
- this.registerColliderWithPhysicsSystem();
- }
- };
- Collider.prototype.registerColliderWithPhysicsSystem = function () {
- if (this._isParentEntityAddedToScene && !this._isColliderRegistered) {
- Physics.addCollider(this);
- this._isColliderRegistered = true;
- }
- };
- Collider.prototype.unregisterColliderWithPhysicsSystem = function () {
- if (this._isParentEntityAddedToScene && this._isColliderRegistered) {
- Physics.removeCollider(this);
- }
- this._isColliderRegistered = false;
- };
- Collider.prototype.overlaps = function (other) {
- return this.shape.overlaps(other.shape);
- };
- Collider.prototype.collidesWith = function (collider, motion) {
- var oldPosition = this.shape.position;
- this.shape.position = Vector2.add(this.shape.position, motion);
- var result = this.shape.collidesWithShape(collider.shape);
- if (result)
- result.collider = collider;
- this.shape.position = oldPosition;
- return result;
- };
- Collider.prototype.onAddedToEntity = function () {
- if (this._colliderRequiresAutoSizing) {
- if (!(this instanceof BoxCollider)) {
- console.error("Only box and circle colliders can be created automatically");
+ };
+ Scene.prototype.addRenderer = function (renderer) {
+ this._renderers.push(renderer);
+ this._renderers.sort();
+ renderer.onAddedToScene(this);
+ return renderer;
+ };
+ Scene.prototype.getRenderer = function (type) {
+ for (var i = 0; i < this._renderers.length; i++) {
+ if (this._renderers[i] instanceof type)
+ return this._renderers[i];
}
- var bounds = this.entity.getBounds();
- var renderbaleBounds = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
- var width = renderbaleBounds.width / this.entity.scale.x;
- var height = renderbaleBounds.height / this.entity.scale.y;
- if (this instanceof BoxCollider) {
- var boxCollider = this;
- boxCollider.width = width;
- boxCollider.height = height;
- this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position);
+ return null;
+ };
+ Scene.prototype.removeRenderer = function (renderer) {
+ if (!this._renderers.contains(renderer))
+ return;
+ this._renderers.remove(renderer);
+ renderer.unload();
+ };
+ Scene.prototype.addPostProcessor = function (postProcessor) {
+ this._postProcessors.push(postProcessor);
+ this._postProcessors.sort();
+ postProcessor.onAddedToScene(this);
+ if (this._didSceneBegin) {
+ postProcessor.onSceneBackBufferSizeChanged(this.stage.stageWidth, this.stage.stageHeight);
}
- }
- this._isParentEntityAddedToScene = true;
- this.registerColliderWithPhysicsSystem();
- };
- Collider.prototype.onRemovedFromEntity = function () {
- this.unregisterColliderWithPhysicsSystem();
- this._isParentEntityAddedToScene = false;
- };
- Collider.prototype.onEnabled = function () {
- this.registerColliderWithPhysicsSystem();
- };
- Collider.prototype.onDisabled = function () {
- this.unregisterColliderWithPhysicsSystem();
- };
- Collider.prototype.onEntityTransformChanged = function (comp) {
- if (this._isColliderRegistered)
- Physics.updateCollider(this);
- };
- return Collider;
-}(Component));
-var BoxCollider = (function (_super) {
- __extends(BoxCollider, _super);
- function BoxCollider() {
- var _this = _super.call(this) || this;
- _this.shape = new Box(1, 1);
- _this._colliderRequiresAutoSizing = true;
- return _this;
- }
- Object.defineProperty(BoxCollider.prototype, "width", {
- get: function () {
- return this.shape.width;
- },
- set: function (value) {
- this.setWidth(value);
- },
- enumerable: true,
- configurable: true
- });
- BoxCollider.prototype.setWidth = function (width) {
- this._colliderRequiresAutoSizing = false;
- var box = this.shape;
- if (width != box.width) {
- box.updateBox(width, box.height);
- if (this.entity && this._isParentEntityAddedToScene)
- Physics.updateCollider(this);
- }
- return this;
- };
- Object.defineProperty(BoxCollider.prototype, "height", {
- get: function () {
- return this.shape.height;
- },
- set: function (value) {
- this.setHeight(value);
- },
- enumerable: true,
- configurable: true
- });
- BoxCollider.prototype.setHeight = function (height) {
- this._colliderRequiresAutoSizing = false;
- var box = this.shape;
- if (height != box.height) {
- box.updateBox(box.width, height);
- if (this.entity && this._isParentEntityAddedToScene)
- Physics.updateCollider(this);
- }
- };
- BoxCollider.prototype.setSize = function (width, height) {
- this._colliderRequiresAutoSizing = false;
- var box = this.shape;
- if (width != box.width || height != box.height) {
- box.updateBox(width, height);
- if (this.entity && this._isParentEntityAddedToScene)
- Physics.updateCollider(this);
- }
- return this;
- };
- return BoxCollider;
-}(Collider));
-var EntitySystem = (function () {
- function EntitySystem(matcher) {
- this._entities = [];
- this._matcher = matcher ? matcher : Matcher.empty();
- }
- Object.defineProperty(EntitySystem.prototype, "matcher", {
- get: function () {
- return this._matcher;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(EntitySystem.prototype, "scene", {
- get: function () {
- return this._scene;
- },
- set: function (value) {
- this._scene = value;
- this._entities = [];
- },
- enumerable: true,
- configurable: true
- });
- EntitySystem.prototype.initialize = function () {
- };
- EntitySystem.prototype.onChanged = function (entity) {
- var contains = this._entities.contains(entity);
- var interest = this._matcher.IsIntersted(entity);
- if (interest && !contains)
- this.add(entity);
- else if (!interest && contains)
- this.remove(entity);
- };
- EntitySystem.prototype.add = function (entity) {
- this._entities.push(entity);
- this.onAdded(entity);
- };
- EntitySystem.prototype.onAdded = function (entity) {
- };
- EntitySystem.prototype.remove = function (entity) {
- this._entities.remove(entity);
- this.onRemoved(entity);
- };
- EntitySystem.prototype.onRemoved = function (entity) {
- };
- EntitySystem.prototype.update = function () {
- this.begin();
- this.process(this._entities);
- };
- EntitySystem.prototype.lateUpdate = function () {
- this.lateProcess(this._entities);
- this.end();
- };
- EntitySystem.prototype.begin = function () {
- };
- EntitySystem.prototype.process = function (entities) {
- };
- EntitySystem.prototype.lateProcess = function (entities) {
- };
- EntitySystem.prototype.end = function () {
- };
- return EntitySystem;
-}());
-var EntityProcessingSystem = (function (_super) {
- __extends(EntityProcessingSystem, _super);
- function EntityProcessingSystem(matcher) {
- return _super.call(this, matcher) || this;
- }
- EntityProcessingSystem.prototype.lateProcessEntity = function (entity) {
- };
- EntityProcessingSystem.prototype.process = function (entities) {
- var _this = this;
- entities.forEach(function (entity) { return _this.processEntity(entity); });
- };
- EntityProcessingSystem.prototype.lateProcess = function (entities) {
- var _this = this;
- entities.forEach(function (entity) { return _this.lateProcessEntity(entity); });
- };
- return EntityProcessingSystem;
-}(EntitySystem));
-var PassiveSystem = (function (_super) {
- __extends(PassiveSystem, _super);
- function PassiveSystem() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- PassiveSystem.prototype.onChanged = function (entity) {
- };
- PassiveSystem.prototype.process = function (entities) {
- this.begin();
- this.end();
- };
- return PassiveSystem;
-}(EntitySystem));
-var ProcessingSystem = (function (_super) {
- __extends(ProcessingSystem, _super);
- function ProcessingSystem() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- ProcessingSystem.prototype.onChanged = function (entity) {
- };
- ProcessingSystem.prototype.process = function (entities) {
- this.begin();
- this.processSystem();
- this.end();
- };
- return ProcessingSystem;
-}(EntitySystem));
-var BitSet = (function () {
- function BitSet(nbits) {
- if (nbits === void 0) { nbits = 64; }
- var length = nbits >> 6;
- if ((nbits & BitSet.LONG_MASK) != 0)
- length++;
- this._bits = new Array(length);
- }
- BitSet.prototype.and = function (bs) {
- var max = Math.min(this._bits.length, bs._bits.length);
- var i;
- for (var i_1 = 0; i_1 < max; ++i_1)
- this._bits[i_1] &= bs._bits[i_1];
- while (i < this._bits.length)
- this._bits[i++] = 0;
- };
- BitSet.prototype.andNot = function (bs) {
- var i = Math.min(this._bits.length, bs._bits.length);
- while (--i >= 0)
- this._bits[i] &= ~bs._bits[i];
- };
- BitSet.prototype.cardinality = function () {
- var card = 0;
- for (var i = this._bits.length - 1; i >= 0; i--) {
- var a = this._bits[i];
- if (a == 0)
- continue;
- if (a == -1) {
- card += 64;
- continue;
+ return postProcessor;
+ };
+ Scene.prototype.getPostProcessor = function (type) {
+ for (var i = 0; i < this._postProcessors.length; i++) {
+ if (this._postProcessors[i] instanceof type)
+ return this._postProcessors[i];
}
- a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555);
- a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333);
- var b = ((a >> 32) + a);
- b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f);
- b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff);
- card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff);
- }
- return card;
- };
- BitSet.prototype.clear = function (pos) {
- if (pos != undefined) {
- var offset = pos >> 6;
- this.ensure(offset);
- this._bits[offset] &= ~(1 << pos);
- }
- else {
- for (var i = 0; i < this._bits.length; i++)
- this._bits[i] = 0;
- }
- };
- BitSet.prototype.ensure = function (lastElt) {
- if (lastElt >= this._bits.length) {
- var nd = new Number[lastElt + 1];
- nd = this._bits.copyWithin(0, 0, this._bits.length);
- this._bits = nd;
- }
- };
- BitSet.prototype.get = function (pos) {
- var offset = pos >> 6;
- if (offset >= this._bits.length)
- return false;
- return (this._bits[offset] & (1 << pos)) != 0;
- };
- BitSet.prototype.intersects = function (set) {
- var i = Math.min(this._bits.length, set._bits.length);
- while (--i >= 0) {
- if ((this._bits[i] & set._bits[i]) != 0)
- return true;
- }
- return false;
- };
- BitSet.prototype.isEmpty = function () {
- for (var i = this._bits.length - 1; i >= 0; i--) {
- if (this._bits[i])
- return false;
- }
- return true;
- };
- BitSet.prototype.nextSetBit = function (from) {
- var offset = from >> 6;
- var mask = 1 << from;
- while (offset < this._bits.length) {
- var h = this._bits[offset];
- do {
- if ((h & mask) != 0)
- return from;
- mask <<= 1;
- from++;
- } while (mask != 0);
- mask = 1;
- offset++;
- }
- return -1;
- };
- BitSet.prototype.set = function (pos, value) {
- if (value === void 0) { value = true; }
- if (value) {
- var offset = pos >> 6;
- this.ensure(offset);
- this._bits[offset] |= 1 << pos;
- }
- else {
- this.clear(pos);
- }
- };
- BitSet.LONG_MASK = 0x3f;
- return BitSet;
-}());
-var ComponentList = (function () {
- function ComponentList(entity) {
- this._components = [];
- this._componentsToAdd = [];
- this._componentsToRemove = [];
- this._tempBufferList = [];
- this._entity = entity;
- }
- Object.defineProperty(ComponentList.prototype, "count", {
- get: function () {
- return this._components.length;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(ComponentList.prototype, "buffer", {
- get: function () {
- return this._components;
- },
- enumerable: true,
- configurable: true
- });
- ComponentList.prototype.add = function (component) {
- this._componentsToAdd.push(component);
- };
- ComponentList.prototype.remove = function (component) {
- if (this._componentsToAdd.contains(component)) {
- this._componentsToAdd.remove(component);
- return;
- }
- this._componentsToRemove.push(component);
- };
- ComponentList.prototype.removeAllComponents = function () {
- for (var i = 0; i < this._components.length; i++) {
- this.handleRemove(this._components[i]);
- }
- this._components.length = 0;
- this._componentsToAdd.length = 0;
- this._componentsToRemove.length = 0;
- };
- ComponentList.prototype.deregisterAllComponents = function () {
- for (var i = 0; i < this._components.length; i++) {
- var component = this._components[i];
- if (component instanceof RenderableComponent)
- this._entity.scene.renderableComponents.remove(component);
- this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false);
- this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
- }
- };
- ComponentList.prototype.registerAllComponents = function () {
- for (var i = 0; i < this._components.length; i++) {
- var component = this._components[i];
- if (component instanceof RenderableComponent)
- this._entity.scene.renderableComponents.add(component);
- this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
- this._entity.scene.entityProcessors.onComponentAdded(this._entity);
- }
- };
- ComponentList.prototype.updateLists = function () {
- if (this._componentsToRemove.length > 0) {
- for (var i = 0; i < this._componentsToRemove.length; i++) {
- this.handleRemove(this._componentsToRemove[i]);
- this._components.remove(this._componentsToRemove[i]);
+ return null;
+ };
+ Scene.prototype.removePostProcessor = function (postProcessor) {
+ if (!this._postProcessors.contains(postProcessor))
+ return;
+ this._postProcessors.remove(postProcessor);
+ postProcessor.unload();
+ };
+ Scene.prototype.createEntity = function (name) {
+ var entity = new es.Entity(name);
+ return this.addEntity(entity);
+ };
+ Scene.prototype.addEntity = function (entity) {
+ if (this.entities.buffer.contains(entity))
+ console.warn("You are attempting to add the same entity to a scene twice: " + entity);
+ this.entities.add(entity);
+ entity.scene = this;
+ for (var i = 0; i < entity.transform.childCount; i++)
+ this.addEntity(entity.transform.getChild(i).entity);
+ return entity;
+ };
+ Scene.prototype.destroyAllEntities = function () {
+ for (var i = 0; i < this.entities.count; i++) {
+ this.entities.buffer[i].destroy();
}
- this._componentsToRemove.length = 0;
+ };
+ Scene.prototype.findEntity = function (name) {
+ return this.entities.findEntity(name);
+ };
+ Scene.prototype.findEntitiesWithTag = function (tag) {
+ return this.entities.entitiesWithTag(tag);
+ };
+ Scene.prototype.entitiesOfType = function (type) {
+ return this.entities.entitiesOfType(type);
+ };
+ Scene.prototype.findComponentOfType = function (type) {
+ return this.entities.findComponentOfType(type);
+ };
+ Scene.prototype.findComponentsOfType = function (type) {
+ return this.entities.findComponentsOfType(type);
+ };
+ Scene.prototype.addEntityProcessor = function (processor) {
+ processor.scene = this;
+ this.entityProcessors.add(processor);
+ return processor;
+ };
+ Scene.prototype.removeEntityProcessor = function (processor) {
+ this.entityProcessors.remove(processor);
+ };
+ Scene.prototype.getEntityProcessor = function () {
+ return this.entityProcessors.getProcessor();
+ };
+ return Scene;
+ }(egret.DisplayObjectContainer));
+ es.Scene = Scene;
+})(es || (es = {}));
+var transform;
+(function (transform) {
+ var Component;
+ (function (Component) {
+ Component[Component["position"] = 0] = "position";
+ Component[Component["scale"] = 1] = "scale";
+ Component[Component["rotation"] = 2] = "rotation";
+ })(Component = transform.Component || (transform.Component = {}));
+})(transform || (transform = {}));
+var es;
+(function (es) {
+ var HashObject = egret.HashObject;
+ var DirtyType;
+ (function (DirtyType) {
+ DirtyType[DirtyType["clean"] = 0] = "clean";
+ DirtyType[DirtyType["positionDirty"] = 1] = "positionDirty";
+ DirtyType[DirtyType["scaleDirty"] = 2] = "scaleDirty";
+ DirtyType[DirtyType["rotationDirty"] = 3] = "rotationDirty";
+ })(DirtyType = es.DirtyType || (es.DirtyType = {}));
+ var Transform = (function (_super) {
+ __extends(Transform, _super);
+ function Transform(entity) {
+ var _this = _super.call(this) || this;
+ _this._localTransform = es.Matrix2D.create();
+ _this._worldTransform = es.Matrix2D.create().identity();
+ _this._rotationMatrix = es.Matrix2D.create();
+ _this._translationMatrix = es.Matrix2D.create();
+ _this._scaleMatrix = es.Matrix2D.create();
+ _this._worldToLocalTransform = es.Matrix2D.create().identity();
+ _this._worldInverseTransform = es.Matrix2D.create().identity();
+ _this._position = es.Vector2.zero;
+ _this._scale = es.Vector2.one;
+ _this._rotation = 0;
+ _this._localPosition = es.Vector2.zero;
+ _this._localScale = es.Vector2.one;
+ _this._localRotation = 0;
+ _this.entity = entity;
+ _this.scale = es.Vector2.one;
+ _this._children = [];
+ return _this;
}
- if (this._componentsToAdd.length > 0) {
- for (var i = 0, count = this._componentsToAdd.length; i < count; i++) {
- var component = this._componentsToAdd[i];
- if (component instanceof RenderableComponent)
- this._entity.scene.renderableComponents.add(component);
- this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
- this._entity.scene.entityProcessors.onComponentAdded(this._entity);
- this._components.push(component);
- this._tempBufferList.push(component);
+ Object.defineProperty(Transform.prototype, "childCount", {
+ get: function () {
+ return this._children.length;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "rotationDegrees", {
+ get: function () {
+ return es.MathHelper.toDegrees(this._rotation);
+ },
+ set: function (value) {
+ this.setRotation(es.MathHelper.toRadians(value));
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "localRotationDegrees", {
+ get: function () {
+ return es.MathHelper.toDegrees(this._localRotation);
+ },
+ set: function (value) {
+ this.localRotation = es.MathHelper.toRadians(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "localToWorldTransform", {
+ get: function () {
+ this.updateTransform();
+ return this._worldTransform;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "parent", {
+ get: function () {
+ return this._parent;
+ },
+ set: function (value) {
+ this.setParent(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "worldToLocalTransform", {
+ get: function () {
+ if (this._worldToLocalDirty) {
+ if (!this.parent) {
+ this._worldToLocalTransform = es.Matrix2D.create().identity();
+ }
+ else {
+ this.parent.updateTransform();
+ this._worldToLocalTransform = this.parent._worldTransform.invert();
+ }
+ this._worldToLocalDirty = false;
+ }
+ return this._worldToLocalTransform;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "worldInverseTransform", {
+ get: function () {
+ this.updateTransform();
+ if (this._worldInverseDirty) {
+ this._worldInverseTransform = this._worldTransform.invert();
+ this._worldInverseDirty = false;
+ }
+ return this._worldInverseTransform;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "position", {
+ get: function () {
+ this.updateTransform();
+ if (this._positionDirty) {
+ if (!this.parent) {
+ this._position = this._localPosition;
+ }
+ else {
+ this.parent.updateTransform();
+ this._position = es.Vector2Ext.transformR(this._localPosition, this.parent._worldTransform);
+ }
+ this._positionDirty = false;
+ }
+ return this._position;
+ },
+ set: function (value) {
+ this.setPosition(value.x, value.y);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "scale", {
+ get: function () {
+ this.updateTransform();
+ return this._scale;
+ },
+ set: function (value) {
+ this.setScale(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "rotation", {
+ get: function () {
+ this.updateTransform();
+ return this._rotation;
+ },
+ set: function (value) {
+ this.setRotation(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "localPosition", {
+ get: function () {
+ this.updateTransform();
+ return this._localPosition;
+ },
+ set: function (value) {
+ this.setLocalPosition(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "localScale", {
+ get: function () {
+ this.updateTransform();
+ return this._localScale;
+ },
+ set: function (value) {
+ this.setLocalScale(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "localRotation", {
+ get: function () {
+ this.updateTransform();
+ return this._localRotation;
+ },
+ set: function (value) {
+ this.setLocalRotation(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Transform.prototype.getChild = function (index) {
+ return this._children[index];
+ };
+ Transform.prototype.setParent = function (parent) {
+ if (this._parent.equals(parent))
+ return this;
+ if (!this._parent) {
+ this._parent._children.remove(this);
+ this._parent._children.push(this);
}
- this._componentsToAdd.length = 0;
- for (var i = 0; i < this._tempBufferList.length; i++) {
- var component = this._tempBufferList[i];
- component.onAddedToEntity();
- if (component.enabled) {
- component.onEnabled();
+ this._parent = parent;
+ this.setDirty(DirtyType.positionDirty);
+ return this;
+ };
+ Transform.prototype.setPosition = function (x, y) {
+ var position = new es.Vector2(x, y);
+ if (position.equals(this._position))
+ return this;
+ this._position = position;
+ if (this.parent) {
+ this.localPosition = es.Vector2Ext.transformR(this._position, this._worldToLocalTransform);
+ }
+ else {
+ this.localPosition = position;
+ }
+ this._positionDirty = false;
+ return this;
+ };
+ Transform.prototype.setLocalPosition = function (localPosition) {
+ if (localPosition.equals(this._localPosition))
+ return this;
+ this._localPosition = localPosition;
+ this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true;
+ this.setDirty(DirtyType.positionDirty);
+ return this;
+ };
+ Transform.prototype.setRotation = function (radians) {
+ this._rotation = radians;
+ if (this.parent) {
+ this.localRotation = this.parent.rotation + radians;
+ }
+ else {
+ this.localRotation = radians;
+ }
+ return this;
+ };
+ Transform.prototype.setRotationDegrees = function (degrees) {
+ return this.setRotation(es.MathHelper.toRadians(degrees));
+ };
+ Transform.prototype.lookAt = function (pos) {
+ var sign = this.position.x > pos.x ? -1 : 1;
+ var vectorToAlignTo = es.Vector2.normalize(es.Vector2.subtract(this.position, pos));
+ this.rotation = sign * Math.acos(es.Vector2.dot(vectorToAlignTo, es.Vector2.unitY));
+ };
+ Transform.prototype.setLocalRotation = function (radians) {
+ this._localRotation = radians;
+ this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true;
+ this.setDirty(DirtyType.rotationDirty);
+ return this;
+ };
+ Transform.prototype.setLocalRotationDegrees = function (degrees) {
+ return this.setLocalRotation(es.MathHelper.toRadians(degrees));
+ };
+ Transform.prototype.setScale = function (scale) {
+ this._scale = scale;
+ if (this.parent) {
+ this.localScale = es.Vector2.divide(scale, this.parent._scale);
+ }
+ else {
+ this.localScale = scale;
+ }
+ return this;
+ };
+ Transform.prototype.setLocalScale = function (scale) {
+ this._localScale = scale;
+ this._localDirty = this._positionDirty = this._localScaleDirty = true;
+ this.setDirty(DirtyType.scaleDirty);
+ return this;
+ };
+ Transform.prototype.roundPosition = function () {
+ this.position = this._position.round();
+ };
+ Transform.prototype.updateTransform = function () {
+ if (this.hierarchyDirty != DirtyType.clean) {
+ if (this.parent)
+ this.parent.updateTransform();
+ if (this._localDirty) {
+ if (this._localPositionDirty) {
+ this._translationMatrix = es.Matrix2D.create().translate(this._localPosition.x, this._localPosition.y);
+ this._localPositionDirty = false;
+ }
+ if (this._localRotationDirty) {
+ this._rotationMatrix = es.Matrix2D.create().rotate(this._localRotation);
+ this._localRotationDirty = false;
+ }
+ if (this._localScaleDirty) {
+ this._scaleMatrix = es.Matrix2D.create().scale(this._localScale.x, this._localScale.y);
+ this._localScaleDirty = false;
+ }
+ this._localTransform = this._scaleMatrix.multiply(this._rotationMatrix);
+ this._localTransform = this._localTransform.multiply(this._translationMatrix);
+ if (!this.parent) {
+ this._worldTransform = this._localTransform;
+ this._rotation = this._localRotation;
+ this._scale = this._localScale;
+ this._worldInverseDirty = true;
+ }
+ this._localDirty = false;
+ }
+ if (this.parent) {
+ this._worldTransform = this._localTransform.multiply(this.parent._worldTransform);
+ this._rotation = this._localRotation + this.parent._rotation;
+ this._scale = es.Vector2.multiply(this.parent._scale, this._localScale);
+ this._worldInverseDirty = true;
+ }
+ this._worldToLocalDirty = true;
+ this._positionDirty = true;
+ this.hierarchyDirty = DirtyType.clean;
+ }
+ };
+ Transform.prototype.setDirty = function (dirtyFlagType) {
+ if ((this.hierarchyDirty & dirtyFlagType) == 0) {
+ this.hierarchyDirty |= dirtyFlagType;
+ switch (dirtyFlagType) {
+ case es.DirtyType.positionDirty:
+ this.entity.onTransformChanged(transform.Component.position);
+ break;
+ case es.DirtyType.rotationDirty:
+ this.entity.onTransformChanged(transform.Component.rotation);
+ break;
+ case es.DirtyType.scaleDirty:
+ this.entity.onTransformChanged(transform.Component.scale);
+ break;
+ }
+ if (!this._children)
+ this._children = [];
+ for (var i = 0; i < this._children.length; i++)
+ this._children[i].setDirty(dirtyFlagType);
+ }
+ };
+ Transform.prototype.copyFrom = function (transform) {
+ this._position = transform.position;
+ this._localPosition = transform._localPosition;
+ this._rotation = transform._rotation;
+ this._localRotation = transform._localRotation;
+ this._scale = transform._scale;
+ this._localScale = transform._localScale;
+ this.setDirty(DirtyType.positionDirty);
+ this.setDirty(DirtyType.rotationDirty);
+ this.setDirty(DirtyType.scaleDirty);
+ };
+ Transform.prototype.toString = function () {
+ return "[Transform: parent: " + this.parent + ", position: " + this.position + ", rotation: " + this.rotation + ",\n scale: " + this.scale + ", localPosition: " + this._localPosition + ", localRotation: " + this._localRotation + ",\n localScale: " + this._localScale + "]";
+ };
+ Transform.prototype.equals = function (other) {
+ return other.hashCode == this.hashCode;
+ };
+ return Transform;
+ }(HashObject));
+ es.Transform = Transform;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var CameraStyle;
+ (function (CameraStyle) {
+ CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn";
+ CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow";
+ })(CameraStyle = es.CameraStyle || (es.CameraStyle = {}));
+ var CameraInset = (function () {
+ function CameraInset() {
+ this.left = 0;
+ this.right = 0;
+ this.top = 0;
+ this.bottom = 0;
+ }
+ return CameraInset;
+ }());
+ es.CameraInset = CameraInset;
+ var Camera = (function (_super) {
+ __extends(Camera, _super);
+ function Camera(targetEntity, cameraStyle) {
+ if (targetEntity === void 0) { targetEntity = null; }
+ if (cameraStyle === void 0) { cameraStyle = CameraStyle.lockOn; }
+ var _this = _super.call(this) || this;
+ _this._inset = new CameraInset();
+ _this._areMatrixedDirty = true;
+ _this._areBoundsDirty = true;
+ _this._isProjectionMatrixDirty = true;
+ _this.followLerp = 0.1;
+ _this.deadzone = new es.Rectangle();
+ _this.focusOffset = es.Vector2.zero;
+ _this.mapLockEnabled = false;
+ _this.mapSize = es.Vector2.zero;
+ _this._desiredPositionDelta = new es.Vector2();
+ _this._worldSpaceDeadZone = new es.Rectangle();
+ _this._minimumZoom = 0.3;
+ _this._maximumZoom = 3;
+ _this._bounds = new es.Rectangle();
+ _this._transformMatrix = new es.Matrix2D().identity();
+ _this._inverseTransformMatrix = new es.Matrix2D().identity();
+ _this._origin = es.Vector2.zero;
+ _this._targetEntity = targetEntity;
+ _this._cameraStyle = cameraStyle;
+ _this.setZoom(0);
+ return _this;
+ }
+ Object.defineProperty(Camera.prototype, "position", {
+ get: function () {
+ return this.entity.transform.position;
+ },
+ set: function (value) {
+ this.entity.transform.position = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "rotation", {
+ get: function () {
+ return this.entity.transform.rotation;
+ },
+ set: function (value) {
+ this.entity.transform.rotation = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "zoom", {
+ get: function () {
+ if (this._zoom == 0)
+ return 1;
+ if (this._zoom < 1)
+ return es.MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0);
+ return es.MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1);
+ },
+ set: function (value) {
+ this.setZoom(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "minimumZoom", {
+ get: function () {
+ return this._minimumZoom;
+ },
+ set: function (value) {
+ this.setMinimumZoom(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "maximumZoom", {
+ get: function () {
+ return this._maximumZoom;
+ },
+ set: function (value) {
+ this.setMaximumZoom(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "bounds", {
+ get: function () {
+ if (this._areMatrixedDirty)
+ this.updateMatrixes();
+ if (this._areBoundsDirty) {
+ var topLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, this._inset.top));
+ var bottomRight = this.screenToWorldPoint(new es.Vector2(es.Core.graphicsDevice.viewport.width - this._inset.right, es.Core.graphicsDevice.viewport.height - this._inset.bottom));
+ if (this.entity.transform.rotation != 0) {
+ var topRight = this.screenToWorldPoint(new es.Vector2(es.Core.graphicsDevice.viewport.width - this._inset.right, this._inset.top));
+ var bottomLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, es.Core.graphicsDevice.viewport.height - this._inset.bottom));
+ var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
+ var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
+ var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
+ var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
+ this._bounds.location = new es.Vector2(minX, minY);
+ this._bounds.width = maxX - minX;
+ this._bounds.height = maxY - minY;
+ }
+ else {
+ this._bounds.location = topLeft;
+ this._bounds.width = bottomRight.x - topLeft.x;
+ this._bounds.height = bottomRight.y - topLeft.y;
+ }
+ this._areBoundsDirty = false;
+ }
+ return this._bounds;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "transformMatrix", {
+ get: function () {
+ if (this._areMatrixedDirty)
+ this.updateMatrixes();
+ return this._transformMatrix;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "inverseTransformMatrix", {
+ get: function () {
+ if (this._areMatrixedDirty)
+ this.updateMatrixes();
+ return this._inverseTransformMatrix;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "origin", {
+ get: function () {
+ return this._origin;
+ },
+ set: function (value) {
+ if (this._origin != value) {
+ this._origin = value;
+ this._areMatrixedDirty = true;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) {
+ var oldOrigin = this._origin;
+ this.origin = new es.Vector2(newWidth / 2, newHeight / 2);
+ this.entity.transform.position = es.Vector2.add(this.entity.transform.position, es.Vector2.subtract(this._origin, oldOrigin));
+ };
+ Camera.prototype.setInset = function (left, right, top, bottom) {
+ this._inset = new CameraInset();
+ this._inset.left = left;
+ this._inset.right = right;
+ this._inset.top = top;
+ this._inset.bottom = bottom;
+ this._areBoundsDirty = true;
+ return this;
+ };
+ Camera.prototype.setPosition = function (position) {
+ this.entity.transform.setPosition(position.x, position.y);
+ return this;
+ };
+ Camera.prototype.setRotation = function (rotation) {
+ this.entity.transform.setRotation(rotation);
+ return this;
+ };
+ Camera.prototype.setZoom = function (zoom) {
+ var newZoom = es.MathHelper.clamp(zoom, -1, 1);
+ if (newZoom == 0) {
+ this._zoom = 1;
+ }
+ else if (newZoom < 0) {
+ this._zoom = es.MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1);
+ }
+ else {
+ this._zoom = es.MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom);
+ }
+ this._areMatrixedDirty = true;
+ return this;
+ };
+ Camera.prototype.setMinimumZoom = function (minZoom) {
+ if (minZoom <= 0) {
+ console.error("minimumZoom must be greater than zero");
+ return;
+ }
+ if (this._zoom < minZoom)
+ this._zoom = this.minimumZoom;
+ this._minimumZoom = minZoom;
+ return this;
+ };
+ Camera.prototype.setMaximumZoom = function (maxZoom) {
+ if (maxZoom <= 0) {
+ console.error("maximumZoom must be greater than zero");
+ return;
+ }
+ if (this._zoom > maxZoom)
+ this._zoom = maxZoom;
+ this._maximumZoom = maxZoom;
+ return this;
+ };
+ Camera.prototype.onEntityTransformChanged = function (comp) {
+ this._areMatrixedDirty = true;
+ };
+ Camera.prototype.zoomIn = function (deltaZoom) {
+ this.zoom += deltaZoom;
+ };
+ Camera.prototype.zoomOut = function (deltaZoom) {
+ this.zoom -= deltaZoom;
+ };
+ Camera.prototype.worldToScreenPoint = function (worldPosition) {
+ this.updateMatrixes();
+ worldPosition = es.Vector2.transform(worldPosition, this._transformMatrix);
+ return worldPosition;
+ };
+ Camera.prototype.screenToWorldPoint = function (screenPosition) {
+ this.updateMatrixes();
+ screenPosition = es.Vector2.transform(screenPosition, this._inverseTransformMatrix);
+ return screenPosition;
+ };
+ Camera.prototype.mouseToWorldPoint = function () {
+ return this.screenToWorldPoint(es.Input.touchPosition);
+ };
+ Camera.prototype.onAddedToEntity = function () {
+ this.follow(this._targetEntity, this._cameraStyle);
+ };
+ Camera.prototype.update = function () {
+ var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5));
+ this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * es.Core.scene.scaleX + this.deadzone.x + this.focusOffset.x;
+ this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * es.Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
+ this._worldSpaceDeadZone.width = this.deadzone.width;
+ this._worldSpaceDeadZone.height = this.deadzone.height;
+ if (this._targetEntity)
+ this.updateFollow();
+ this.position = es.Vector2.lerp(this.position, es.Vector2.add(this.position, this._desiredPositionDelta), this.followLerp);
+ this.entity.transform.roundPosition();
+ if (this.mapLockEnabled) {
+ this.position = this.clampToMapSize(this.position);
+ this.entity.transform.roundPosition();
+ }
+ };
+ Camera.prototype.clampToMapSize = function (position) {
+ var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5));
+ var cameraMax = new es.Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y);
+ return es.Vector2.clamp(position, halfScreen, cameraMax);
+ };
+ Camera.prototype.updateFollow = function () {
+ this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0;
+ if (this._cameraStyle == CameraStyle.lockOn) {
+ var targetX = this._targetEntity.transform.position.x;
+ var targetY = this._targetEntity.transform.position.y;
+ if (this._worldSpaceDeadZone.x > targetX)
+ this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
+ else if (this._worldSpaceDeadZone.x < targetX)
+ this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
+ if (this._worldSpaceDeadZone.y < targetY)
+ this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
+ else if (this._worldSpaceDeadZone.y > targetY)
+ this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
+ }
+ else {
+ if (!this._targetCollider) {
+ this._targetCollider = this._targetEntity.getComponent(es.Collider);
+ if (!this._targetCollider)
+ return;
+ }
+ var targetBounds = this._targetEntity.getComponent(es.Collider).bounds;
+ if (!this._worldSpaceDeadZone.containsRect(targetBounds)) {
+ if (this._worldSpaceDeadZone.left > targetBounds.left)
+ this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left;
+ else if (this._worldSpaceDeadZone.right < targetBounds.right)
+ this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right;
+ if (this._worldSpaceDeadZone.bottom < targetBounds.bottom)
+ this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom;
+ else if (this._worldSpaceDeadZone.top > targetBounds.top)
+ this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top;
}
}
- this._tempBufferList.length = 0;
+ };
+ Camera.prototype.follow = function (targetEntity, cameraStyle) {
+ if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; }
+ this._targetEntity = targetEntity;
+ this._cameraStyle = cameraStyle;
+ switch (this._cameraStyle) {
+ case CameraStyle.cameraWindow:
+ var w = this.bounds.width / 6;
+ var h = this.bounds.height / 3;
+ this.deadzone = new es.Rectangle((this.bounds.width - w) / 2, (this.bounds.height - h) / 2, w, h);
+ break;
+ case CameraStyle.lockOn:
+ this.deadzone = new es.Rectangle(this.bounds.width / 2, this.bounds.height / 2, 10, 10);
+ break;
+ }
+ };
+ Camera.prototype.setCenteredDeadzone = function (width, height) {
+ this.deadzone = new es.Rectangle((this.bounds.width - width) / 2, (this.bounds.height - height) / 2, width, height);
+ };
+ Camera.prototype.updateMatrixes = function () {
+ if (!this._areMatrixedDirty)
+ return;
+ var tempMat;
+ this._transformMatrix = es.Matrix2D.create().translate(-this.entity.transform.position.x, -this.entity.transform.position.y);
+ if (this._zoom != 1) {
+ tempMat = es.Matrix2D.create().scale(this._zoom, this._zoom);
+ this._transformMatrix = this._transformMatrix.multiply(tempMat);
+ }
+ if (this.entity.transform.rotation != 0) {
+ tempMat = es.Matrix2D.create().rotate(this.entity.transform.rotation);
+ this._transformMatrix = this._transformMatrix.multiply(tempMat);
+ }
+ tempMat = es.Matrix2D.create().translate(this._origin.x, this._origin.y);
+ this._transformMatrix = this._transformMatrix.multiply(tempMat);
+ this._inverseTransformMatrix = this._transformMatrix.invert();
+ this._areBoundsDirty = true;
+ this._areMatrixedDirty = false;
+ };
+ return Camera;
+ }(es.Component));
+ es.Camera = Camera;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var ComponentPool = (function () {
+ function ComponentPool(typeClass) {
+ this._type = typeClass;
+ this._cache = [];
}
- };
- ComponentList.prototype.onEntityTransformChanged = function (comp) {
- for (var i = 0; i < this._components.length; i++) {
- if (this._components[i].enabled)
- this._components[i].onEntityTransformChanged(comp);
+ ComponentPool.prototype.obtain = function () {
+ try {
+ return this._cache.length > 0 ? this._cache.shift() : new this._type();
+ }
+ catch (err) {
+ throw new Error(this._type + err);
+ }
+ };
+ ComponentPool.prototype.free = function (component) {
+ component.reset();
+ this._cache.push(component);
+ };
+ return ComponentPool;
+ }());
+ es.ComponentPool = ComponentPool;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var IUpdatableComparer = (function () {
+ function IUpdatableComparer() {
}
- for (var i = 0; i < this._componentsToAdd.length; i++) {
- if (this._componentsToAdd[i].enabled)
- this._componentsToAdd[i].onEntityTransformChanged(comp);
+ IUpdatableComparer.prototype.compare = function (a, b) {
+ return a.updateOrder - b.updateOrder;
+ };
+ return IUpdatableComparer;
+ }());
+ es.IUpdatableComparer = IUpdatableComparer;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var PooledComponent = (function (_super) {
+ __extends(PooledComponent, _super);
+ function PooledComponent() {
+ return _super !== null && _super.apply(this, arguments) || this;
}
- };
- ComponentList.prototype.handleRemove = function (component) {
- if (component instanceof RenderableComponent)
- this._entity.scene.renderableComponents.remove(component);
- this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false);
- this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
- component.onRemovedFromEntity();
- component.entity = null;
- };
- ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) {
- for (var i = 0; i < this._components.length; i++) {
- var component = this._components[i];
- if (component instanceof type)
- return component;
+ return PooledComponent;
+ }(es.Component));
+ es.PooledComponent = PooledComponent;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var RenderableComponent = (function (_super) {
+ __extends(RenderableComponent, _super);
+ function RenderableComponent() {
+ var _this = _super !== null && _super.apply(this, arguments) || this;
+ _this.displayObject = new egret.DisplayObject();
+ _this.color = 0x000000;
+ _this._areBoundsDirty = true;
+ _this._localOffset = es.Vector2.zero;
+ _this._renderLayer = 0;
+ _this._bounds = new es.Rectangle();
+ return _this;
}
- if (!onlyReturnInitializedComponents) {
- for (var i = 0; i < this._componentsToAdd.length; i++) {
- var component = this._componentsToAdd[i];
+ Object.defineProperty(RenderableComponent.prototype, "width", {
+ get: function () {
+ return this.bounds.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RenderableComponent.prototype, "height", {
+ get: function () {
+ return this.bounds.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RenderableComponent.prototype, "localOffset", {
+ get: function () {
+ return this._localOffset;
+ },
+ set: function (value) {
+ this.setLocalOffset(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RenderableComponent.prototype, "renderLayer", {
+ get: function () {
+ return this._renderLayer;
+ },
+ set: function (value) {
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RenderableComponent.prototype, "bounds", {
+ get: function () {
+ if (this._areBoundsDirty) {
+ this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, es.Vector2.zero, this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
+ this._areBoundsDirty = false;
+ }
+ return this._bounds;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RenderableComponent.prototype, "isVisible", {
+ get: function () {
+ return this._isVisible;
+ },
+ set: function (value) {
+ if (this._isVisible != value) {
+ this._isVisible = value;
+ if (this._isVisible)
+ this.onBecameVisible();
+ else
+ this.onBecameInvisible();
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ RenderableComponent.prototype.onEntityTransformChanged = function (comp) {
+ this._areBoundsDirty = true;
+ };
+ RenderableComponent.prototype.isVisibleFromCamera = function (camera) {
+ this.isVisible = camera.bounds.intersects(this.bounds);
+ return this.isVisible;
+ };
+ RenderableComponent.prototype.setRenderLayer = function (renderLayer) {
+ if (renderLayer != this._renderLayer) {
+ var oldRenderLayer = this._renderLayer;
+ this._renderLayer = renderLayer;
+ if (this.entity && this.entity.scene)
+ this.entity.scene.renderableComponents.updateRenderableRenderLayer(this, oldRenderLayer, this._renderLayer);
+ }
+ return this;
+ };
+ RenderableComponent.prototype.setColor = function (color) {
+ this.color = color;
+ return this;
+ };
+ RenderableComponent.prototype.setLocalOffset = function (offset) {
+ if (this._localOffset != offset) {
+ this._localOffset = offset;
+ }
+ return this;
+ };
+ RenderableComponent.prototype.sync = function (camera) {
+ this.displayObject.x = this.entity.position.x + this.localOffset.x - camera.position.x + camera.origin.x;
+ this.displayObject.y = this.entity.position.y + this.localOffset.y - camera.position.y + camera.origin.y;
+ this.displayObject.scaleX = this.entity.scale.x;
+ this.displayObject.scaleY = this.entity.scale.y;
+ this.displayObject.rotation = this.entity.rotation;
+ };
+ RenderableComponent.prototype.toString = function () {
+ return "[RenderableComponent] renderLayer: " + this.renderLayer;
+ };
+ RenderableComponent.prototype.onBecameVisible = function () {
+ this.displayObject.visible = this.isVisible;
+ };
+ RenderableComponent.prototype.onBecameInvisible = function () {
+ this.displayObject.visible = this.isVisible;
+ };
+ return RenderableComponent;
+ }(es.Component));
+ es.RenderableComponent = RenderableComponent;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Mesh = (function (_super) {
+ __extends(Mesh, _super);
+ function Mesh() {
+ var _this = _super.call(this) || this;
+ _this._mesh = new egret.Mesh();
+ return _this;
+ }
+ Mesh.prototype.setTexture = function (texture) {
+ this._mesh.texture = texture;
+ this._mesh.$renderNode = new egret.sys.RenderNode();
+ return this;
+ };
+ Mesh.prototype.reset = function () {
+ };
+ Mesh.prototype.render = function (camera) {
+ };
+ return Mesh;
+ }(es.RenderableComponent));
+ es.Mesh = Mesh;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Bitmap = egret.Bitmap;
+ var SpriteRenderer = (function (_super) {
+ __extends(SpriteRenderer, _super);
+ function SpriteRenderer(sprite) {
+ if (sprite === void 0) { sprite = null; }
+ var _this = _super.call(this) || this;
+ if (sprite instanceof es.Sprite)
+ _this.setSprite(sprite);
+ else if (sprite instanceof egret.Texture)
+ _this.setSprite(new es.Sprite(sprite));
+ return _this;
+ }
+ Object.defineProperty(SpriteRenderer.prototype, "bounds", {
+ get: function () {
+ if (this._areBoundsDirty) {
+ if (this._sprite) {
+ this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.sourceRect.width, this._sprite.sourceRect.height);
+ this._areBoundsDirty = false;
+ }
+ }
+ return this._bounds;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(SpriteRenderer.prototype, "originNormalized", {
+ get: function () {
+ return new es.Vector2(this._origin.x / this.width * this.entity.transform.scale.x, this._origin.y / this.height * this.entity.transform.scale.y);
+ },
+ set: function (value) {
+ this.setOrigin(new es.Vector2(value.x * this.width / this.entity.transform.scale.x, value.y * this.height / this.entity.transform.scale.y));
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(SpriteRenderer.prototype, "origin", {
+ get: function () {
+ return this._origin;
+ },
+ set: function (value) {
+ this.setOrigin(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(SpriteRenderer.prototype, "sprite", {
+ get: function () {
+ return this._sprite;
+ },
+ set: function (value) {
+ this.setSprite(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ SpriteRenderer.prototype.setSprite = function (sprite) {
+ this._sprite = sprite;
+ if (this._sprite) {
+ this._origin = this._sprite.origin;
+ this.displayObject.anchorOffsetX = this._origin.x;
+ this.displayObject.anchorOffsetY = this._origin.y;
+ }
+ this.displayObject = new Bitmap(sprite.texture2D);
+ return this;
+ };
+ SpriteRenderer.prototype.setOrigin = function (origin) {
+ if (this._origin != origin) {
+ this._origin = origin;
+ this.displayObject.anchorOffsetX = this._origin.x;
+ this.displayObject.anchorOffsetY = this._origin.y;
+ this._areBoundsDirty = true;
+ }
+ return this;
+ };
+ SpriteRenderer.prototype.setOriginNormalized = function (value) {
+ this.setOrigin(new es.Vector2(value.x * this.width / this.entity.transform.scale.x, value.y * this.height / this.entity.transform.scale.y));
+ return this;
+ };
+ SpriteRenderer.prototype.render = function (camera) {
+ this.sync(camera);
+ this.displayObject.x = this.entity.position.x - this.origin.x + this.localOffset.x - camera.position.x + camera.origin.x;
+ this.displayObject.y = this.entity.position.y - this.origin.y + this.localOffset.y - camera.position.y + camera.origin.y;
+ };
+ return SpriteRenderer;
+ }(es.RenderableComponent));
+ es.SpriteRenderer = SpriteRenderer;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var TiledSpriteRenderer = (function (_super) {
+ __extends(TiledSpriteRenderer, _super);
+ function TiledSpriteRenderer(sprite) {
+ var _this = _super.call(this, sprite) || this;
+ _this._sourceRect = new es.Rectangle();
+ _this._textureScale = es.Vector2.one;
+ _this._inverseTexScale = es.Vector2.one;
+ _this._sourceRect = sprite.sourceRect;
+ var bitmap = _this.displayObject;
+ bitmap.$fillMode = egret.BitmapFillMode.REPEAT;
+ return _this;
+ }
+ Object.defineProperty(TiledSpriteRenderer.prototype, "bounds", {
+ get: function () {
+ if (this._areBoundsDirty) {
+ if (this._sprite) {
+ this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
+ this._areBoundsDirty = false;
+ }
+ }
+ return this._bounds;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", {
+ get: function () {
+ return this._sourceRect.x;
+ },
+ set: function (value) {
+ this._sourceRect.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", {
+ get: function () {
+ return this._sourceRect.y;
+ },
+ set: function (value) {
+ this._sourceRect.y = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TiledSpriteRenderer.prototype, "textureScale", {
+ get: function () {
+ return this._textureScale;
+ },
+ set: function (value) {
+ this._textureScale = value;
+ this._inverseTexScale = new es.Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
+ this._sourceRect.width = this._sprite.sourceRect.width * this._inverseTexScale.x;
+ this._sourceRect.height = this._sprite.sourceRect.height * this._inverseTexScale.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TiledSpriteRenderer.prototype, "width", {
+ get: function () {
+ return this._sourceRect.width;
+ },
+ set: function (value) {
+ this._areBoundsDirty = true;
+ this._sourceRect.width = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TiledSpriteRenderer.prototype, "height", {
+ get: function () {
+ return this._sourceRect.height;
+ },
+ set: function (value) {
+ this._areBoundsDirty = true;
+ this._sourceRect.height = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ TiledSpriteRenderer.prototype.render = function (camera) {
+ var bitmap = this.displayObject;
+ bitmap.width = this.width;
+ bitmap.height = this.height;
+ _super.prototype.render.call(this, camera);
+ };
+ return TiledSpriteRenderer;
+ }(es.SpriteRenderer));
+ es.TiledSpriteRenderer = TiledSpriteRenderer;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var ScrollingSpriteRenderer = (function (_super) {
+ __extends(ScrollingSpriteRenderer, _super);
+ function ScrollingSpriteRenderer(sprite) {
+ var _this = _super.call(this, sprite) || this;
+ _this.scrollSpeedX = 15;
+ _this.scroolSpeedY = 0;
+ _this._scrollX = 0;
+ _this._scrollY = 0;
+ return _this;
+ }
+ Object.defineProperty(ScrollingSpriteRenderer.prototype, "textureScale", {
+ get: function () {
+ return this._textureScale;
+ },
+ set: function (value) {
+ this._textureScale = value;
+ this._inverseTexScale = new es.Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ ScrollingSpriteRenderer.prototype.update = function () {
+ this._scrollX += this.scrollSpeedX * es.Time.deltaTime;
+ this._scrollY += this.scroolSpeedY * es.Time.deltaTime;
+ this._sourceRect.x = this._scrollX;
+ this._sourceRect.y = this._scrollY;
+ };
+ return ScrollingSpriteRenderer;
+ }(es.TiledSpriteRenderer));
+ es.ScrollingSpriteRenderer = ScrollingSpriteRenderer;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Sprite = (function () {
+ function Sprite(texture, sourceRect, origin) {
+ if (sourceRect === void 0) { sourceRect = new es.Rectangle(0, 0, texture.textureWidth, texture.textureHeight); }
+ if (origin === void 0) { origin = sourceRect.getHalfSize(); }
+ this.uvs = new es.Rectangle();
+ this.texture2D = texture;
+ this.sourceRect = sourceRect;
+ this.center = new es.Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5);
+ this.origin = origin;
+ var inverseTexW = 1 / texture.textureWidth;
+ var inverseTexH = 1 / texture.textureHeight;
+ this.uvs.x = sourceRect.x * inverseTexW;
+ this.uvs.y = sourceRect.y * inverseTexH;
+ this.uvs.width = sourceRect.width * inverseTexW;
+ this.uvs.height = sourceRect.height * inverseTexH;
+ }
+ return Sprite;
+ }());
+ es.Sprite = Sprite;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var SpriteAnimation = (function () {
+ function SpriteAnimation(sprites, frameRate) {
+ this.sprites = sprites;
+ this.frameRate = frameRate;
+ }
+ return SpriteAnimation;
+ }());
+ es.SpriteAnimation = SpriteAnimation;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var LoopMode;
+ (function (LoopMode) {
+ LoopMode[LoopMode["loop"] = 0] = "loop";
+ LoopMode[LoopMode["once"] = 1] = "once";
+ LoopMode[LoopMode["clampForever"] = 2] = "clampForever";
+ LoopMode[LoopMode["pingPong"] = 3] = "pingPong";
+ LoopMode[LoopMode["pingPongOnce"] = 4] = "pingPongOnce";
+ })(LoopMode = es.LoopMode || (es.LoopMode = {}));
+ var State;
+ (function (State) {
+ State[State["none"] = 0] = "none";
+ State[State["running"] = 1] = "running";
+ State[State["paused"] = 2] = "paused";
+ State[State["completed"] = 3] = "completed";
+ })(State = es.State || (es.State = {}));
+ var SpriteAnimator = (function (_super) {
+ __extends(SpriteAnimator, _super);
+ function SpriteAnimator(sprite) {
+ var _this = _super.call(this, sprite) || this;
+ _this.speed = 1;
+ _this.animationState = State.none;
+ _this._elapsedTime = 0;
+ _this._animations = new Map();
+ return _this;
+ }
+ Object.defineProperty(SpriteAnimator.prototype, "isRunning", {
+ get: function () {
+ return this.animationState == State.running;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(SpriteAnimator.prototype, "animations", {
+ get: function () {
+ return this._animations;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ SpriteAnimator.prototype.update = function () {
+ if (this.animationState != State.running || !this.currentAnimation)
+ return;
+ var animation = this.currentAnimation;
+ var secondsPerFrame = 1 / (animation.frameRate * this.speed);
+ var iterationDuration = secondsPerFrame * animation.sprites.length;
+ this._elapsedTime += es.Time.deltaTime;
+ var time = Math.abs(this._elapsedTime);
+ if (this._loopMode == LoopMode.once && time > iterationDuration ||
+ this._loopMode == LoopMode.pingPongOnce && time > iterationDuration * 2) {
+ this.animationState = State.completed;
+ this._elapsedTime = 0;
+ this.currentFrame = 0;
+ this.sprite = animation.sprites[this.currentFrame];
+ return;
+ }
+ var i = Math.floor(time / secondsPerFrame);
+ var n = animation.sprites.length;
+ if (n > 2 && (this._loopMode == LoopMode.pingPong || this._loopMode == LoopMode.pingPongOnce)) {
+ var maxIndex = n - 1;
+ this.currentFrame = maxIndex - Math.abs(maxIndex - i % (maxIndex * 2));
+ }
+ else {
+ this.currentFrame = i % n;
+ }
+ this.sprite = animation.sprites[this.currentFrame];
+ };
+ SpriteAnimator.prototype.addAnimation = function (name, animation) {
+ if (!this.sprite && animation.sprites.length > 0)
+ this.setSprite(animation.sprites[0]);
+ this._animations[name] = animation;
+ return this;
+ };
+ SpriteAnimator.prototype.play = function (name, loopMode) {
+ if (loopMode === void 0) { loopMode = null; }
+ this.currentAnimation = this._animations[name];
+ this.currentAnimationName = name;
+ this.currentFrame = 0;
+ this.animationState = State.running;
+ this.sprite = this.currentAnimation.sprites[0];
+ this._elapsedTime = 0;
+ this._loopMode = loopMode ? loopMode : LoopMode.loop;
+ };
+ SpriteAnimator.prototype.isAnimationActive = function (name) {
+ return this.currentAnimation && this.currentAnimationName == name;
+ };
+ SpriteAnimator.prototype.pause = function () {
+ this.animationState = State.paused;
+ };
+ SpriteAnimator.prototype.unPause = function () {
+ this.animationState = State.running;
+ };
+ SpriteAnimator.prototype.stop = function () {
+ this.currentAnimation = null;
+ this.currentAnimationName = null;
+ this.currentFrame = 0;
+ this.animationState = State.none;
+ };
+ return SpriteAnimator;
+ }(es.SpriteRenderer));
+ es.SpriteAnimator = SpriteAnimator;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Mover = (function (_super) {
+ __extends(Mover, _super);
+ function Mover() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ Mover.prototype.onAddedToEntity = function () {
+ this._triggerHelper = new es.ColliderTriggerHelper(this.entity);
+ };
+ Mover.prototype.calculateMovement = function (motion, collisionResult) {
+ if (!this.entity.getComponent(es.Collider) || !this._triggerHelper) {
+ return false;
+ }
+ var colliders = this.entity.getComponents(es.Collider);
+ for (var i = 0; i < colliders.length; i++) {
+ var collider = colliders[i];
+ if (collider.isTrigger)
+ continue;
+ var bounds = collider.bounds;
+ bounds.x += motion.x;
+ bounds.y += motion.y;
+ var neighbors = es.Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers);
+ for (var j = 0; j < neighbors.length; j++) {
+ var neighbor = neighbors[j];
+ if (neighbor.isTrigger)
+ continue;
+ var _internalcollisionResult = new es.CollisionResult();
+ if (collider.collidesWith(neighbor, motion, _internalcollisionResult)) {
+ motion = motion.subtract(_internalcollisionResult.minimumTranslationVector);
+ if (_internalcollisionResult.collider != null) {
+ collisionResult = _internalcollisionResult;
+ }
+ }
+ }
+ }
+ es.ListPool.free(colliders);
+ return collisionResult.collider != null;
+ };
+ Mover.prototype.applyMovement = function (motion) {
+ this.entity.position = es.Vector2.add(this.entity.position, motion);
+ if (this._triggerHelper)
+ this._triggerHelper.update();
+ };
+ Mover.prototype.move = function (motion, collisionResult) {
+ this.calculateMovement(motion, collisionResult);
+ this.applyMovement(motion);
+ return collisionResult.collider != null;
+ };
+ return Mover;
+ }(es.Component));
+ es.Mover = Mover;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var ProjectileMover = (function (_super) {
+ __extends(ProjectileMover, _super);
+ function ProjectileMover() {
+ var _this = _super !== null && _super.apply(this, arguments) || this;
+ _this._tempTriggerList = [];
+ return _this;
+ }
+ ProjectileMover.prototype.onAddedToEntity = function () {
+ this._collider = this.entity.getComponent(es.Collider);
+ if (!this._collider)
+ console.warn("ProjectileMover has no Collider. ProjectilMover requires a Collider!");
+ };
+ ProjectileMover.prototype.move = function (motion) {
+ if (!this._collider)
+ return false;
+ var didCollide = false;
+ this.entity.position = es.Vector2.add(this.entity.position, motion);
+ var neighbors = es.Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers);
+ for (var i = 0; i < neighbors.length; i++) {
+ var neighbor = neighbors[i];
+ if (this._collider.overlaps(neighbor) && neighbor.enabled) {
+ didCollide = true;
+ this.notifyTriggerListeners(this._collider, neighbor);
+ }
+ }
+ return didCollide;
+ };
+ ProjectileMover.prototype.notifyTriggerListeners = function (self, other) {
+ other.entity.getComponents("ITriggerListener", this._tempTriggerList);
+ for (var i = 0; i < this._tempTriggerList.length; i++) {
+ this._tempTriggerList[i].onTriggerEnter(self, other);
+ }
+ this._tempTriggerList.length = 0;
+ this.entity.getComponents("ITriggerListener", this._tempTriggerList);
+ for (var i = 0; i < this._tempTriggerList.length; i++) {
+ this._tempTriggerList[i].onTriggerEnter(other, self);
+ }
+ this._tempTriggerList.length = 0;
+ };
+ return ProjectileMover;
+ }(es.Component));
+ es.ProjectileMover = ProjectileMover;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Collider = (function (_super) {
+ __extends(Collider, _super);
+ function Collider() {
+ var _this = _super !== null && _super.apply(this, arguments) || this;
+ _this.physicsLayer = 1 << 0;
+ _this.collidesWithLayers = es.Physics.allLayers;
+ _this.shouldColliderScaleAndRotateWithTransform = true;
+ _this.registeredPhysicsBounds = new es.Rectangle();
+ _this._isPositionDirty = true;
+ _this._isRotationDirty = true;
+ _this._localOffset = es.Vector2.zero;
+ return _this;
+ }
+ Object.defineProperty(Collider.prototype, "absolutePosition", {
+ get: function () {
+ return es.Vector2.add(this.entity.transform.position, this._localOffset);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Collider.prototype, "rotation", {
+ get: function () {
+ if (this.shouldColliderScaleAndRotateWithTransform && this.entity)
+ return this.entity.transform.rotation;
+ return 0;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Collider.prototype, "bounds", {
+ get: function () {
+ if (this._isPositionDirty || this._isRotationDirty) {
+ this.shape.recalculateBounds(this);
+ this._isPositionDirty = this._isRotationDirty = false;
+ }
+ return this.shape.bounds;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Collider.prototype, "localOffset", {
+ get: function () {
+ return this._localOffset;
+ },
+ set: function (value) {
+ this.setLocalOffset(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Collider.prototype.setLocalOffset = function (offset) {
+ if (this._localOffset != offset) {
+ this.unregisterColliderWithPhysicsSystem();
+ this._localOffset = offset;
+ this._localOffsetLength = this._localOffset.length();
+ this._isPositionDirty = true;
+ this.registerColliderWithPhysicsSystem();
+ }
+ return this;
+ };
+ Collider.prototype.setShouldColliderScaleAndRotateWithTransform = function (shouldColliderScaleAndRotationWithTransform) {
+ this.shouldColliderScaleAndRotateWithTransform = shouldColliderScaleAndRotationWithTransform;
+ this._isPositionDirty = this._isRotationDirty = true;
+ return this;
+ };
+ Collider.prototype.onAddedToEntity = function () {
+ if (this._colliderRequiresAutoSizing) {
+ if (!(this instanceof es.BoxCollider || this instanceof es.CircleCollider)) {
+ console.error("Only box and circle colliders can be created automatically");
+ return;
+ }
+ var renderable = this.entity.getComponent(es.RenderableComponent);
+ if (renderable) {
+ var renderableBounds = renderable.bounds;
+ var width = renderableBounds.width / this.entity.scale.x;
+ var height = renderableBounds.height / this.entity.scale.y;
+ if (this instanceof es.CircleCollider) {
+ this.radius = Math.max(width, height) * 0.5;
+ }
+ else {
+ this.width = width;
+ this.height = height;
+ }
+ this.localOffset = es.Vector2.subtract(renderableBounds.center, this.entity.transform.position);
+ }
+ else {
+ console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it.");
+ }
+ }
+ this._isParentEntityAddedToScene = true;
+ this.registerColliderWithPhysicsSystem();
+ };
+ Collider.prototype.onRemovedFromEntity = function () {
+ this.unregisterColliderWithPhysicsSystem();
+ this._isParentEntityAddedToScene = false;
+ };
+ Collider.prototype.onEntityTransformChanged = function (comp) {
+ switch (comp) {
+ case transform.Component.position:
+ this._isPositionDirty = true;
+ break;
+ case transform.Component.scale:
+ this._isPositionDirty = true;
+ break;
+ case transform.Component.rotation:
+ this._isRotationDirty = true;
+ break;
+ }
+ if (this._isColliderRegistered)
+ es.Physics.updateCollider(this);
+ };
+ Collider.prototype.onEnabled = function () {
+ this.registerColliderWithPhysicsSystem();
+ this._isPositionDirty = this._isRotationDirty = true;
+ };
+ Collider.prototype.onDisabled = function () {
+ this.unregisterColliderWithPhysicsSystem();
+ };
+ Collider.prototype.registerColliderWithPhysicsSystem = function () {
+ if (this._isParentEntityAddedToScene && !this._isColliderRegistered) {
+ es.Physics.addCollider(this);
+ this._isColliderRegistered = true;
+ }
+ };
+ Collider.prototype.unregisterColliderWithPhysicsSystem = function () {
+ if (this._isParentEntityAddedToScene && this._isColliderRegistered) {
+ es.Physics.removeCollider(this);
+ }
+ this._isColliderRegistered = false;
+ };
+ Collider.prototype.overlaps = function (other) {
+ return this.shape.overlaps(other.shape);
+ };
+ Collider.prototype.collidesWith = function (collider, motion, result) {
+ var oldPosition = this.entity.position;
+ this.entity.position = this.entity.position.add(motion);
+ var didCollide = this.shape.collidesWithShape(collider.shape, result);
+ if (didCollide)
+ result.collider = collider;
+ this.entity.position = oldPosition;
+ return didCollide;
+ };
+ Collider.prototype.clone = function () {
+ var collider = ObjectUtils.clone(this);
+ collider.entity = null;
+ if (this.shape)
+ collider.shape = this.shape.clone();
+ return collider;
+ };
+ return Collider;
+ }(es.Component));
+ es.Collider = Collider;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var BoxCollider = (function (_super) {
+ __extends(BoxCollider, _super);
+ function BoxCollider() {
+ var _this = _super.call(this) || this;
+ _this.shape = new es.Box(1, 1);
+ _this._colliderRequiresAutoSizing = true;
+ return _this;
+ }
+ Object.defineProperty(BoxCollider.prototype, "width", {
+ get: function () {
+ return this.shape.width;
+ },
+ set: function (value) {
+ this.setWidth(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(BoxCollider.prototype, "height", {
+ get: function () {
+ return this.shape.height;
+ },
+ set: function (value) {
+ this.setHeight(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ BoxCollider.prototype.setSize = function (width, height) {
+ this._colliderRequiresAutoSizing = false;
+ var box = this.shape;
+ if (width != box.width || height != box.height) {
+ box.updateBox(width, height);
+ if (this.entity && this._isParentEntityAddedToScene)
+ es.Physics.updateCollider(this);
+ }
+ return this;
+ };
+ BoxCollider.prototype.setWidth = function (width) {
+ this._colliderRequiresAutoSizing = false;
+ var box = this.shape;
+ if (width != box.width) {
+ box.updateBox(width, box.height);
+ if (this.entity && this._isParentEntityAddedToScene)
+ es.Physics.updateCollider(this);
+ }
+ return this;
+ };
+ BoxCollider.prototype.setHeight = function (height) {
+ this._colliderRequiresAutoSizing = false;
+ var box = this.shape;
+ if (height != box.height) {
+ box.updateBox(box.width, height);
+ if (this.entity && this._isParentEntityAddedToScene)
+ es.Physics.updateCollider(this);
+ }
+ };
+ BoxCollider.prototype.toString = function () {
+ return "[BoxCollider: bounds: " + this.bounds + "]";
+ };
+ return BoxCollider;
+ }(es.Collider));
+ es.BoxCollider = BoxCollider;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var CircleCollider = (function (_super) {
+ __extends(CircleCollider, _super);
+ function CircleCollider(radius) {
+ var _this = _super.call(this) || this;
+ if (radius)
+ _this._colliderRequiresAutoSizing = true;
+ _this.shape = new es.Circle(radius ? radius : 1);
+ return _this;
+ }
+ Object.defineProperty(CircleCollider.prototype, "radius", {
+ get: function () {
+ return this.shape.radius;
+ },
+ set: function (value) {
+ this.setRadius(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ CircleCollider.prototype.setRadius = function (radius) {
+ this._colliderRequiresAutoSizing = false;
+ var circle = this.shape;
+ if (radius != circle.radius) {
+ circle.radius = radius;
+ circle._originalRadius = radius;
+ if (this.entity && this._isParentEntityAddedToScene)
+ es.Physics.updateCollider(this);
+ }
+ return this;
+ };
+ CircleCollider.prototype.toString = function () {
+ return "[CircleCollider: bounds: " + this.bounds + ", radius: " + this.shape.radius + "]";
+ };
+ return CircleCollider;
+ }(es.Collider));
+ es.CircleCollider = CircleCollider;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var PolygonCollider = (function (_super) {
+ __extends(PolygonCollider, _super);
+ function PolygonCollider(points) {
+ var _this = _super.call(this) || this;
+ var isPolygonClosed = points[0] == points[points.length - 1];
+ if (isPolygonClosed)
+ points.splice(points.length - 1, 1);
+ var center = es.Polygon.findPolygonCenter(points);
+ _this.setLocalOffset(center);
+ es.Polygon.recenterPolygonVerts(points);
+ _this.shape = new es.Polygon(points);
+ return _this;
+ }
+ return PolygonCollider;
+ }(es.Collider));
+ es.PolygonCollider = PolygonCollider;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var EntitySystem = (function () {
+ function EntitySystem(matcher) {
+ this._entities = [];
+ this._matcher = matcher ? matcher : es.Matcher.empty();
+ }
+ Object.defineProperty(EntitySystem.prototype, "scene", {
+ get: function () {
+ return this._scene;
+ },
+ set: function (value) {
+ this._scene = value;
+ this._entities = [];
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(EntitySystem.prototype, "matcher", {
+ get: function () {
+ return this._matcher;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ EntitySystem.prototype.initialize = function () {
+ };
+ EntitySystem.prototype.onChanged = function (entity) {
+ var contains = this._entities.contains(entity);
+ var interest = this._matcher.IsIntersted(entity);
+ if (interest && !contains)
+ this.add(entity);
+ else if (!interest && contains)
+ this.remove(entity);
+ };
+ EntitySystem.prototype.add = function (entity) {
+ this._entities.push(entity);
+ this.onAdded(entity);
+ };
+ EntitySystem.prototype.onAdded = function (entity) {
+ };
+ EntitySystem.prototype.remove = function (entity) {
+ this._entities.remove(entity);
+ this.onRemoved(entity);
+ };
+ EntitySystem.prototype.onRemoved = function (entity) {
+ };
+ EntitySystem.prototype.update = function () {
+ this.begin();
+ this.process(this._entities);
+ };
+ EntitySystem.prototype.lateUpdate = function () {
+ this.lateProcess(this._entities);
+ this.end();
+ };
+ EntitySystem.prototype.begin = function () {
+ };
+ EntitySystem.prototype.process = function (entities) {
+ };
+ EntitySystem.prototype.lateProcess = function (entities) {
+ };
+ EntitySystem.prototype.end = function () {
+ };
+ return EntitySystem;
+ }());
+ es.EntitySystem = EntitySystem;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var EntityProcessingSystem = (function (_super) {
+ __extends(EntityProcessingSystem, _super);
+ function EntityProcessingSystem(matcher) {
+ return _super.call(this, matcher) || this;
+ }
+ EntityProcessingSystem.prototype.lateProcessEntity = function (entity) {
+ };
+ EntityProcessingSystem.prototype.process = function (entities) {
+ var _this = this;
+ entities.forEach(function (entity) { return _this.processEntity(entity); });
+ };
+ EntityProcessingSystem.prototype.lateProcess = function (entities) {
+ var _this = this;
+ entities.forEach(function (entity) { return _this.lateProcessEntity(entity); });
+ };
+ return EntityProcessingSystem;
+ }(es.EntitySystem));
+ es.EntityProcessingSystem = EntityProcessingSystem;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var PassiveSystem = (function (_super) {
+ __extends(PassiveSystem, _super);
+ function PassiveSystem() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ PassiveSystem.prototype.onChanged = function (entity) {
+ };
+ PassiveSystem.prototype.process = function (entities) {
+ this.begin();
+ this.end();
+ };
+ return PassiveSystem;
+ }(es.EntitySystem));
+ es.PassiveSystem = PassiveSystem;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var ProcessingSystem = (function (_super) {
+ __extends(ProcessingSystem, _super);
+ function ProcessingSystem() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ ProcessingSystem.prototype.onChanged = function (entity) {
+ };
+ ProcessingSystem.prototype.process = function (entities) {
+ this.begin();
+ this.processSystem();
+ this.end();
+ };
+ return ProcessingSystem;
+ }(es.EntitySystem));
+ es.ProcessingSystem = ProcessingSystem;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var BitSet = (function () {
+ function BitSet(nbits) {
+ if (nbits === void 0) { nbits = 64; }
+ var length = nbits >> 6;
+ if ((nbits & BitSet.LONG_MASK) != 0)
+ length++;
+ this._bits = new Array(length);
+ }
+ BitSet.prototype.and = function (bs) {
+ var max = Math.min(this._bits.length, bs._bits.length);
+ var i;
+ for (var i_1 = 0; i_1 < max; ++i_1)
+ this._bits[i_1] &= bs._bits[i_1];
+ while (i < this._bits.length)
+ this._bits[i++] = 0;
+ };
+ BitSet.prototype.andNot = function (bs) {
+ var i = Math.min(this._bits.length, bs._bits.length);
+ while (--i >= 0)
+ this._bits[i] &= ~bs._bits[i];
+ };
+ BitSet.prototype.cardinality = function () {
+ var card = 0;
+ for (var i = this._bits.length - 1; i >= 0; i--) {
+ var a = this._bits[i];
+ if (a == 0)
+ continue;
+ if (a == -1) {
+ card += 64;
+ continue;
+ }
+ a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555);
+ a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333);
+ var b = ((a >> 32) + a);
+ b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f);
+ b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff);
+ card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff);
+ }
+ return card;
+ };
+ BitSet.prototype.clear = function (pos) {
+ if (pos != undefined) {
+ var offset = pos >> 6;
+ this.ensure(offset);
+ this._bits[offset] &= ~(1 << pos);
+ }
+ else {
+ for (var i = 0; i < this._bits.length; i++)
+ this._bits[i] = 0;
+ }
+ };
+ BitSet.prototype.get = function (pos) {
+ var offset = pos >> 6;
+ if (offset >= this._bits.length)
+ return false;
+ return (this._bits[offset] & (1 << pos)) != 0;
+ };
+ BitSet.prototype.intersects = function (set) {
+ var i = Math.min(this._bits.length, set._bits.length);
+ while (--i >= 0) {
+ if ((this._bits[i] & set._bits[i]) != 0)
+ return true;
+ }
+ return false;
+ };
+ BitSet.prototype.isEmpty = function () {
+ for (var i = this._bits.length - 1; i >= 0; i--) {
+ if (this._bits[i])
+ return false;
+ }
+ return true;
+ };
+ BitSet.prototype.nextSetBit = function (from) {
+ var offset = from >> 6;
+ var mask = 1 << from;
+ while (offset < this._bits.length) {
+ var h = this._bits[offset];
+ do {
+ if ((h & mask) != 0)
+ return from;
+ mask <<= 1;
+ from++;
+ } while (mask != 0);
+ mask = 1;
+ offset++;
+ }
+ return -1;
+ };
+ BitSet.prototype.set = function (pos, value) {
+ if (value === void 0) { value = true; }
+ if (value) {
+ var offset = pos >> 6;
+ this.ensure(offset);
+ this._bits[offset] |= 1 << pos;
+ }
+ else {
+ this.clear(pos);
+ }
+ };
+ BitSet.prototype.ensure = function (lastElt) {
+ if (lastElt >= this._bits.length) {
+ var nd = new Number[lastElt + 1];
+ nd = this._bits.copyWithin(0, 0, this._bits.length);
+ this._bits = nd;
+ }
+ };
+ BitSet.LONG_MASK = 0x3f;
+ return BitSet;
+ }());
+ es.BitSet = BitSet;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var ComponentList = (function () {
+ function ComponentList(entity) {
+ this._components = [];
+ this._componentsToAdd = [];
+ this._componentsToRemove = [];
+ this._tempBufferList = [];
+ this._entity = entity;
+ }
+ Object.defineProperty(ComponentList.prototype, "count", {
+ get: function () {
+ return this._components.length;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(ComponentList.prototype, "buffer", {
+ get: function () {
+ return this._components;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ ComponentList.prototype.markEntityListUnsorted = function () {
+ this._isComponentListUnsorted = true;
+ };
+ ComponentList.prototype.add = function (component) {
+ this._componentsToAdd.push(component);
+ };
+ ComponentList.prototype.remove = function (component) {
+ if (this._componentsToRemove.contains(component))
+ console.warn("You are trying to remove a Component (" + component + ") that you already removed");
+ if (this._componentsToAdd.contains(component)) {
+ this._componentsToAdd.remove(component);
+ return;
+ }
+ this._componentsToRemove.push(component);
+ };
+ ComponentList.prototype.removeAllComponents = function () {
+ for (var i = 0; i < this._components.length; i++) {
+ this.handleRemove(this._components[i]);
+ }
+ this._components.length = 0;
+ this._componentsToAdd.length = 0;
+ this._componentsToRemove.length = 0;
+ };
+ ComponentList.prototype.deregisterAllComponents = function () {
+ for (var i = 0; i < this._components.length; i++) {
+ var component = this._components[i];
+ if (component instanceof es.RenderableComponent) {
+ this._entity.scene.removeChild(component.displayObject);
+ this._entity.scene.renderableComponents.remove(component);
+ }
+ this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
+ this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
+ }
+ };
+ ComponentList.prototype.registerAllComponents = function () {
+ for (var i = 0; i < this._components.length; i++) {
+ var component = this._components[i];
+ if (component instanceof es.RenderableComponent) {
+ this._entity.scene.addChild(component.displayObject);
+ this._entity.scene.renderableComponents.add(component);
+ }
+ this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
+ this._entity.scene.entityProcessors.onComponentAdded(this._entity);
+ }
+ };
+ ComponentList.prototype.updateLists = function () {
+ if (this._componentsToRemove.length > 0) {
+ for (var i = 0; i < this._componentsToRemove.length; i++) {
+ this.handleRemove(this._componentsToRemove[i]);
+ this._components.remove(this._componentsToRemove[i]);
+ }
+ this._componentsToRemove.length = 0;
+ }
+ if (this._componentsToAdd.length > 0) {
+ for (var i = 0, count = this._componentsToAdd.length; i < count; i++) {
+ var component = this._componentsToAdd[i];
+ if (component instanceof es.RenderableComponent) {
+ this._entity.scene.addChild(component.displayObject);
+ this._entity.scene.renderableComponents.add(component);
+ }
+ this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
+ this._entity.scene.entityProcessors.onComponentAdded(this._entity);
+ this._components.push(component);
+ this._tempBufferList.push(component);
+ }
+ this._componentsToAdd.length = 0;
+ this._isComponentListUnsorted = true;
+ for (var i = 0; i < this._tempBufferList.length; i++) {
+ var component = this._tempBufferList[i];
+ component.onAddedToEntity();
+ if (component.enabled) {
+ component.onEnabled();
+ }
+ }
+ this._tempBufferList.length = 0;
+ }
+ if (this._isComponentListUnsorted) {
+ this._components.sort(ComponentList.compareUpdatableOrder.compare);
+ this._isComponentListUnsorted = false;
+ }
+ };
+ ComponentList.prototype.handleRemove = function (component) {
+ if (component instanceof es.RenderableComponent) {
+ this._entity.scene.removeChild(component.displayObject);
+ this._entity.scene.renderableComponents.remove(component);
+ }
+ this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
+ this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
+ component.onRemovedFromEntity();
+ component.entity = null;
+ };
+ ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) {
+ for (var i = 0; i < this._components.length; i++) {
+ var component = this._components[i];
if (component instanceof type)
return component;
}
- }
- return null;
- };
- ComponentList.prototype.getComponents = function (typeName, components) {
- if (!components)
- components = [];
- for (var i = 0; i < this._components.length; i++) {
- var component = this._components[i];
- if (typeof (typeName) == "string") {
- if (egret.is(component, typeName)) {
- components.push(component);
+ if (!onlyReturnInitializedComponents) {
+ for (var i = 0; i < this._componentsToAdd.length; i++) {
+ var component = this._componentsToAdd[i];
+ if (component instanceof type)
+ return component;
}
}
- else {
- if (component instanceof typeName) {
- components.push(component);
+ return null;
+ };
+ ComponentList.prototype.getComponents = function (typeName, components) {
+ if (!components)
+ components = [];
+ for (var i = 0; i < this._components.length; i++) {
+ var component = this._components[i];
+ if (typeof (typeName) == "string") {
+ if (egret.is(component, typeName)) {
+ components.push(component);
+ }
+ }
+ else {
+ if (component instanceof typeName) {
+ components.push(component);
+ }
}
}
- }
- for (var i = 0; i < this._componentsToAdd.length; i++) {
- var component = this._componentsToAdd[i];
- if (typeof (typeName) == "string") {
- if (egret.is(component, typeName)) {
- components.push(component);
+ for (var i = 0; i < this._componentsToAdd.length; i++) {
+ var component = this._componentsToAdd[i];
+ if (typeof (typeName) == "string") {
+ if (egret.is(component, typeName)) {
+ components.push(component);
+ }
+ }
+ else {
+ if (component instanceof typeName) {
+ components.push(component);
+ }
}
}
- else {
- if (component instanceof typeName) {
- components.push(component);
- }
+ return components;
+ };
+ ComponentList.prototype.update = function () {
+ this.updateLists();
+ for (var i = 0; i < this._components.length; i++) {
+ var updatableComponent = this._components[i];
+ if (updatableComponent.enabled &&
+ (updatableComponent.updateInterval == 1 ||
+ es.Time.frameCount % updatableComponent.updateInterval == 0))
+ updatableComponent.update();
}
+ };
+ ComponentList.prototype.onEntityTransformChanged = function (comp) {
+ for (var i = 0; i < this._components.length; i++) {
+ if (this._components[i].enabled)
+ this._components[i].onEntityTransformChanged(comp);
+ }
+ for (var i = 0; i < this._componentsToAdd.length; i++) {
+ if (this._componentsToAdd[i].enabled)
+ this._componentsToAdd[i].onEntityTransformChanged(comp);
+ }
+ };
+ ComponentList.prototype.onEntityEnabled = function () {
+ for (var i = 0; i < this._components.length; i++)
+ this._components[i].onEnabled();
+ };
+ ComponentList.prototype.onEntityDisabled = function () {
+ for (var i = 0; i < this._components.length; i++)
+ this._components[i].onDisabled();
+ };
+ ComponentList.compareUpdatableOrder = new es.IUpdatableComparer();
+ return ComponentList;
+ }());
+ es.ComponentList = ComponentList;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var ComponentTypeManager = (function () {
+ function ComponentTypeManager() {
}
- return components;
- };
- ComponentList.prototype.update = function () {
- this.updateLists();
- for (var i = 0; i < this._components.length; i++) {
- var component = this._components[i];
- if (component.enabled && (component.updateInterval == 1 || Time.frameCount % component.updateInterval == 0))
- component.update();
+ ComponentTypeManager.add = function (type) {
+ if (!this._componentTypesMask.has(type))
+ this._componentTypesMask[type] = this._componentTypesMask.size;
+ };
+ ComponentTypeManager.getIndexFor = function (type) {
+ var v = -1;
+ if (!this._componentTypesMask.has(type)) {
+ this.add(type);
+ v = this._componentTypesMask.get(type);
+ }
+ return v;
+ };
+ ComponentTypeManager._componentTypesMask = new Map();
+ return ComponentTypeManager;
+ }());
+ es.ComponentTypeManager = ComponentTypeManager;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var EntityList = (function () {
+ function EntityList(scene) {
+ this._entities = [];
+ this._entitiesToAdded = [];
+ this._entitiesToRemove = [];
+ this._entityDict = new Map();
+ this._unsortedTags = [];
+ this._tempEntityList = [];
+ this.scene = scene;
}
- };
- return ComponentList;
-}());
-var ComponentTypeManager = (function () {
- function ComponentTypeManager() {
- }
- ComponentTypeManager.add = function (type) {
- if (!this._componentTypesMask.has(type))
- this._componentTypesMask[type] = this._componentTypesMask.size;
- };
- ComponentTypeManager.getIndexFor = function (type) {
- var v = -1;
- if (!this._componentTypesMask.has(type)) {
- this.add(type);
- v = this._componentTypesMask.get(type);
- }
- return v;
- };
- ComponentTypeManager._componentTypesMask = new Map();
- return ComponentTypeManager;
-}());
-var EntityList = (function () {
- function EntityList(scene) {
- this._entitiesToRemove = [];
- this._entitiesToAdded = [];
- this._tempEntityList = [];
- this._entities = [];
- this._entityDict = new Map();
- this._unsortedTags = [];
- this.scene = scene;
- }
- Object.defineProperty(EntityList.prototype, "count", {
- get: function () {
- return this._entities.length;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(EntityList.prototype, "buffer", {
- get: function () {
- return this._entities;
- },
- enumerable: true,
- configurable: true
- });
- EntityList.prototype.add = function (entity) {
- if (this._entitiesToAdded.indexOf(entity) == -1)
- this._entitiesToAdded.push(entity);
- };
- EntityList.prototype.remove = function (entity) {
- if (this._entitiesToAdded.contains(entity)) {
- this._entitiesToAdded.remove(entity);
- return;
- }
- if (!this._entitiesToRemove.contains(entity))
- this._entitiesToRemove.push(entity);
- };
- EntityList.prototype.findEntity = function (name) {
- for (var i = 0; i < this._entities.length; i++) {
- if (this._entities[i].name == name)
- return this._entities[i];
- }
- return this._entitiesToAdded.firstOrDefault(function (entity) { return entity.name == name; });
- };
- EntityList.prototype.getTagList = function (tag) {
- var list = this._entityDict.get(tag);
- if (!list) {
- list = [];
- this._entityDict.set(tag, list);
- }
- return this._entityDict.get(tag);
- };
- EntityList.prototype.addToTagList = function (entity) {
- var list = this.getTagList(entity.tag);
- if (!list.contains(entity)) {
- list.push(entity);
- this._unsortedTags.push(entity.tag);
- }
- };
- EntityList.prototype.removeFromTagList = function (entity) {
- var list = this._entityDict.get(entity.tag);
- if (list) {
- list.remove(entity);
- }
- };
- EntityList.prototype.update = function () {
- for (var i = 0; i < this._entities.length; i++) {
- var entity = this._entities[i];
- if (entity.enabled)
- entity.update();
- }
- };
- EntityList.prototype.removeAllEntities = function () {
- this._entitiesToAdded.length = 0;
- this.updateLists();
- for (var i = 0; i < this._entities.length; i++) {
- this._entities[i]._isDestoryed = true;
- this._entities[i].onRemovedFromScene();
- this._entities[i].scene = null;
- }
- this._entities.length = 0;
- this._entityDict.clear();
- };
- EntityList.prototype.updateLists = function () {
- var _this = this;
- if (this._entitiesToRemove.length > 0) {
- var temp = this._entitiesToRemove;
- this._entitiesToRemove = this._tempEntityList;
- this._tempEntityList = temp;
- this._tempEntityList.forEach(function (entity) {
- _this._entities.remove(entity);
- entity.scene = null;
- _this.scene.entityProcessors.onEntityRemoved(entity);
- });
- this._tempEntityList.length = 0;
- }
- if (this._entitiesToAdded.length > 0) {
- var temp = this._entitiesToAdded;
- this._entitiesToAdded = this._tempEntityList;
- this._tempEntityList = temp;
- this._tempEntityList.forEach(function (entity) {
- if (!_this._entities.contains(entity)) {
- _this._entities.push(entity);
- entity.scene = _this.scene;
- _this.scene.entityProcessors.onEntityAdded(entity);
- }
- });
- this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); });
- this._tempEntityList.length = 0;
- }
- if (this._unsortedTags.length > 0) {
- this._unsortedTags.forEach(function (tag) {
- _this._entityDict.get(tag).sort();
- });
+ Object.defineProperty(EntityList.prototype, "count", {
+ get: function () {
+ return this._entities.length;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(EntityList.prototype, "buffer", {
+ get: function () {
+ return this._entities;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ EntityList.prototype.markEntityListUnsorted = function () {
+ this._isEntityListUnsorted = true;
+ };
+ EntityList.prototype.markTagUnsorted = function (tag) {
+ this._unsortedTags.push(tag);
+ };
+ EntityList.prototype.add = function (entity) {
+ if (this._entitiesToAdded.indexOf(entity) == -1)
+ this._entitiesToAdded.push(entity);
+ };
+ EntityList.prototype.remove = function (entity) {
+ if (!this._entitiesToRemove.contains(entity)) {
+ console.warn("You are trying to remove an entity (" + entity.name + ") that you already removed");
+ return;
+ }
+ if (this._entitiesToAdded.contains(entity)) {
+ this._entitiesToAdded.remove(entity);
+ return;
+ }
+ if (!this._entitiesToRemove.contains(entity))
+ this._entitiesToRemove.push(entity);
+ };
+ EntityList.prototype.removeAllEntities = function () {
this._unsortedTags.length = 0;
- }
- };
- return EntityList;
-}());
-var EntityProcessorList = (function () {
- function EntityProcessorList() {
- this._processors = [];
- }
- EntityProcessorList.prototype.add = function (processor) {
- this._processors.push(processor);
- };
- EntityProcessorList.prototype.remove = function (processor) {
- this._processors.remove(processor);
- };
- EntityProcessorList.prototype.onComponentAdded = function (entity) {
- this.notifyEntityChanged(entity);
- };
- EntityProcessorList.prototype.onComponentRemoved = function (entity) {
- this.notifyEntityChanged(entity);
- };
- EntityProcessorList.prototype.onEntityAdded = function (entity) {
- this.notifyEntityChanged(entity);
- };
- EntityProcessorList.prototype.onEntityRemoved = function (entity) {
- this.removeFromProcessors(entity);
- };
- EntityProcessorList.prototype.notifyEntityChanged = function (entity) {
- for (var i = 0; i < this._processors.length; i++) {
- this._processors[i].onChanged(entity);
- }
- };
- EntityProcessorList.prototype.removeFromProcessors = function (entity) {
- for (var i = 0; i < this._processors.length; i++) {
- this._processors[i].remove(entity);
- }
- };
- EntityProcessorList.prototype.begin = function () {
- };
- EntityProcessorList.prototype.update = function () {
- for (var i = 0; i < this._processors.length; i++) {
- this._processors[i].update();
- }
- };
- EntityProcessorList.prototype.lateUpdate = function () {
- for (var i = 0; i < this._processors.length; i++) {
- this._processors[i].lateUpdate();
- }
- };
- EntityProcessorList.prototype.end = function () {
- };
- EntityProcessorList.prototype.getProcessor = function () {
- for (var i = 0; i < this._processors.length; i++) {
- var processor = this._processors[i];
- if (processor instanceof EntitySystem)
- return processor;
- }
- return null;
- };
- return EntityProcessorList;
-}());
-var Matcher = (function () {
- function Matcher() {
- this.allSet = new BitSet();
- this.exclusionSet = new BitSet();
- this.oneSet = new BitSet();
- }
- Matcher.empty = function () {
- return new Matcher();
- };
- Matcher.prototype.getAllSet = function () {
- return this.allSet;
- };
- Matcher.prototype.getExclusionSet = function () {
- return this.exclusionSet;
- };
- Matcher.prototype.getOneSet = function () {
- return this.oneSet;
- };
- Matcher.prototype.IsIntersted = function (e) {
- if (!this.allSet.isEmpty()) {
- for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) {
- if (!e.componentBits.get(i))
- return false;
+ this._entitiesToAdded.length = 0;
+ this._isEntityListUnsorted = false;
+ this.updateLists();
+ for (var i = 0; i < this._entities.length; i++) {
+ this._entities[i]._isDestroyed = true;
+ this._entities[i].onRemovedFromScene();
+ this._entities[i].scene = null;
}
- }
- if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits))
- return false;
- if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits))
- return false;
- return true;
- };
- Matcher.prototype.all = function () {
- var _this = this;
- var types = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- types[_i] = arguments[_i];
- }
- types.forEach(function (type) {
- _this.allSet.set(ComponentTypeManager.getIndexFor(type));
- });
- return this;
- };
- Matcher.prototype.exclude = function () {
- var _this = this;
- var types = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- types[_i] = arguments[_i];
- }
- types.forEach(function (type) {
- _this.exclusionSet.set(ComponentTypeManager.getIndexFor(type));
- });
- return this;
- };
- Matcher.prototype.one = function () {
- var _this = this;
- var types = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- types[_i] = arguments[_i];
- }
- types.forEach(function (type) {
- _this.oneSet.set(ComponentTypeManager.getIndexFor(type));
- });
- return this;
- };
- return Matcher;
-}());
-var RenderableComponentList = (function () {
- function RenderableComponentList() {
- this._components = [];
- }
- Object.defineProperty(RenderableComponentList.prototype, "count", {
- get: function () {
- return this._components.length;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(RenderableComponentList.prototype, "buffer", {
- get: function () {
- return this._components;
- },
- enumerable: true,
- configurable: true
- });
- RenderableComponentList.prototype.add = function (component) {
- this._components.push(component);
- };
- RenderableComponentList.prototype.remove = function (component) {
- this._components.remove(component);
- };
- RenderableComponentList.prototype.updateList = function () {
- };
- return RenderableComponentList;
-}());
-var Time = (function () {
- function Time() {
- }
- ;
- Time.update = function (currentTime) {
- var dt = (currentTime - this._lastTime) / 1000;
- this.deltaTime = dt * this.timeScale;
- this.unscaledDeltaTime = dt;
- this.frameCount++;
- this._lastTime = currentTime;
- };
- Time.deltaTime = 0;
- Time.timeScale = 1;
- Time.frameCount = 0;
- Time._lastTime = 0;
- return Time;
-}());
-var GraphicsCapabilities = (function () {
- function GraphicsCapabilities() {
- }
- GraphicsCapabilities.prototype.initialize = function (device) {
- this.platformInitialize(device);
- };
- GraphicsCapabilities.prototype.platformInitialize = function (device) {
- var gl = new egret.sys.RenderBuffer().context.getInstance();
- this.supportsNonPowerOfTwo = false;
- this.supportsTextureFilterAnisotropic = gl.getExtension("EXT_texture_filter_anisotropic") != null;
- this.supportsDepth24 = true;
- this.supportsPackedDepthStencil = true;
- this.supportsDepthNonLinear = false;
- this.supportsTextureMaxLevel = true;
- this.supportsS3tc = gl.getExtension("WEBGL_compressed_texture_s3tc") != null ||
- gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") != null;
- this.supportsDxt1 = this.supportsS3tc;
- this.supportsPvrtc = false;
- this.supportsAtitc = gl.getExtension("WEBGL_compressed_texture_astc") != null;
- this.supportsFramebufferObjectARB = false;
- };
- return GraphicsCapabilities;
-}());
-var GraphicsDevice = (function () {
- function GraphicsDevice() {
- this.graphicsCapabilities = new GraphicsCapabilities();
- this.graphicsCapabilities.initialize(this);
- }
- return GraphicsDevice;
-}());
-var Viewport = (function () {
- function Viewport(x, y, width, height) {
- this._x = x;
- this._y = y;
- this._width = width;
- this._height = height;
- this._minDepth = 0;
- this._maxDepth = 1;
- }
- Object.defineProperty(Viewport.prototype, "aspectRatio", {
- get: function () {
- if ((this._height != 0) && (this._width != 0))
- return (this._width / this._height);
- return 0;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Viewport.prototype, "bounds", {
- get: function () {
- return new Rectangle(this._x, this._y, this._width, this._height);
- },
- set: function (value) {
- this._x = value.x;
- this._y = value.y;
- this._width = value.width;
- this._height = value.height;
- },
- enumerable: true,
- configurable: true
- });
- return Viewport;
-}());
-var GaussianBlurEffect = (function (_super) {
- __extends(GaussianBlurEffect, _super);
- function GaussianBlurEffect() {
- return _super.call(this, PostProcessor.default_vert, GaussianBlurEffect.blur_frag, {
- screenWidth: SceneManager.stage.stageWidth,
- screenHeight: SceneManager.stage.stageHeight
- }) || this;
- }
- GaussianBlurEffect.blur_frag = "precision mediump float;\n" +
- "uniform sampler2D uSampler;\n" +
- "uniform float screenWidth;\n" +
- "uniform float screenHeight;\n" +
- "float normpdf(in float x, in float sigma)\n" +
- "{\n" +
- "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" +
- "}\n" +
- "void main()\n" +
- "{\n" +
- "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" +
- "const int mSize = 11;\n" +
- "const int kSize = (mSize - 1)/2;\n" +
- "float kernel[mSize];\n" +
- "vec3 final_colour = vec3(0.0);\n" +
- "float sigma = 7.0;\n" +
- "float z = 0.0;\n" +
- "for (int j = 0; j <= kSize; ++j)\n" +
- "{\n" +
- "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" +
- "}\n" +
- "for (int j = 0; j < mSize; ++j)\n" +
- "{\n" +
- "z += kernel[j];\n" +
- "}\n" +
- "for (int i = -kSize; i <= kSize; ++i)\n" +
- "{\n" +
- "for (int j = -kSize; j <= kSize; ++j)\n" +
- "{\n" +
- "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" +
- "}\n}\n" +
- "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" +
- "}";
- return GaussianBlurEffect;
-}(egret.CustomFilter));
-var PolygonLightEffect = (function (_super) {
- __extends(PolygonLightEffect, _super);
- function PolygonLightEffect() {
- return _super.call(this, PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc) || this;
- }
- PolygonLightEffect.vertSrc = "attribute vec2 aVertexPosition;\n" +
- "attribute vec2 aTextureCoord;\n" +
- "uniform vec2 projectionVector;\n" +
- "varying vec2 vTextureCoord;\n" +
- "const vec2 center = vec2(-1.0, 1.0);\n" +
- "void main(void) {\n" +
- " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
- " vTextureCoord = aTextureCoord;\n" +
- "}";
- PolygonLightEffect.fragmentSrc = "precision lowp float;\n" +
- "varying vec2 vTextureCoord;\n" +
- "uniform sampler2D uSampler;\n" +
- "#define SAMPLE_COUNT 15\n" +
- "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" +
- "uniform float _sampleWeights[SAMPLE_COUNT];\n" +
- "void main(void) {\n" +
- "vec4 c = vec4(0, 0, 0, 0);\n" +
- "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
- " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
- "gl_FragColor = c;\n" +
- "}";
- return PolygonLightEffect;
-}(egret.CustomFilter));
-var PostProcessor = (function () {
- function PostProcessor(effect) {
- if (effect === void 0) { effect = null; }
- this.enable = true;
- this.effect = effect;
- }
- PostProcessor.prototype.onAddedToScene = function (scene) {
- this.scene = scene;
- this.shape = new egret.Shape();
- this.shape.graphics.beginFill(0xFFFFFF, 1);
- this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
- this.shape.graphics.endFill();
- scene.addChild(this.shape);
- };
- PostProcessor.prototype.process = function () {
- this.drawFullscreenQuad();
- };
- PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { };
- PostProcessor.prototype.drawFullscreenQuad = function () {
- this.scene.filters = [this.effect];
- };
- PostProcessor.prototype.unload = function () {
- if (this.effect) {
- this.effect = null;
- }
- this.scene.removeChild(this.shape);
- this.scene = null;
- };
- PostProcessor.default_vert = "attribute vec2 aVertexPosition;\n" +
- "attribute vec2 aTextureCoord;\n" +
- "attribute vec2 aColor;\n" +
- "uniform vec2 projectionVector;\n" +
- "varying vec2 vTextureCoord;\n" +
- "varying vec4 vColor;\n" +
- "const vec2 center = vec2(-1.0, 1.0);\n" +
- "void main(void) {\n" +
- "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
- "vTextureCoord = aTextureCoord;\n" +
- "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" +
- "}";
- return PostProcessor;
-}());
-var GaussianBlurPostProcessor = (function (_super) {
- __extends(GaussianBlurPostProcessor, _super);
- function GaussianBlurPostProcessor() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) {
- _super.prototype.onAddedToScene.call(this, scene);
- this.effect = new GaussianBlurEffect();
- };
- return GaussianBlurPostProcessor;
-}(PostProcessor));
-var Renderer = (function () {
- function Renderer() {
- }
- Renderer.prototype.onAddedToScene = function (scene) { };
- Renderer.prototype.beginRender = function (cam) {
- };
- Renderer.prototype.unload = function () { };
- Renderer.prototype.renderAfterStateCheck = function (renderable, cam) {
- renderable.render(cam);
- };
- return Renderer;
-}());
-var DefaultRenderer = (function (_super) {
- __extends(DefaultRenderer, _super);
- function DefaultRenderer() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- DefaultRenderer.prototype.render = function (scene) {
- var cam = this.camera ? this.camera : scene.camera;
- this.beginRender(cam);
- for (var i = 0; i < scene.renderableComponents.count; i++) {
- var renderable = scene.renderableComponents.buffer[i];
- if (renderable.enabled && renderable.isVisibleFromCamera(cam))
- this.renderAfterStateCheck(renderable, cam);
- }
- };
- return DefaultRenderer;
-}(Renderer));
-var ScreenSpaceRenderer = (function (_super) {
- __extends(ScreenSpaceRenderer, _super);
- function ScreenSpaceRenderer() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- ScreenSpaceRenderer.prototype.render = function (scene) {
- };
- return ScreenSpaceRenderer;
-}(Renderer));
-var PolyLight = (function (_super) {
- __extends(PolyLight, _super);
- function PolyLight(radius, color, power) {
- var _this = _super.call(this) || this;
- _this._indices = [];
- _this.radius = radius;
- _this.power = power;
- _this.color = color;
- _this.computeTriangleIndices();
- return _this;
- }
- Object.defineProperty(PolyLight.prototype, "radius", {
- get: function () {
- return this._radius;
- },
- set: function (value) {
- this.setRadius(value);
- },
- enumerable: true,
- configurable: true
- });
- PolyLight.prototype.computeTriangleIndices = function (totalTris) {
- if (totalTris === void 0) { totalTris = 20; }
- this._indices.length = 0;
- for (var i = 0; i < totalTris; i += 2) {
- this._indices.push(0);
- this._indices.push(i + 2);
- this._indices.push(i + 1);
- }
- };
- PolyLight.prototype.setRadius = function (radius) {
- if (radius != this._radius) {
- this._radius = radius;
- this._areBoundsDirty = true;
- }
- };
- PolyLight.prototype.render = function (camera) {
- };
- PolyLight.prototype.reset = function () {
- };
- return PolyLight;
-}(RenderableComponent));
-var SceneTransition = (function () {
- function SceneTransition(sceneLoadAction) {
- this.sceneLoadAction = sceneLoadAction;
- this.loadsNewScene = sceneLoadAction != null;
- }
- Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", {
- get: function () {
- if (!this._hasPreviousSceneRender) {
- this._hasPreviousSceneRender = true;
- return false;
+ this._entities.length = 0;
+ this._entityDict.clear();
+ };
+ EntityList.prototype.contains = function (entity) {
+ return this._entities.contains(entity) || this._entitiesToAdded.contains(entity);
+ };
+ EntityList.prototype.getTagList = function (tag) {
+ var list = this._entityDict.get(tag);
+ if (!list) {
+ list = [];
+ this._entityDict.set(tag, list);
}
- return true;
- },
- enumerable: true,
- configurable: true
- });
- SceneTransition.prototype.preRender = function () { };
- SceneTransition.prototype.render = function () {
- };
- SceneTransition.prototype.onBeginTransition = function () {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0: return [4, this.loadNextScene()];
- case 1:
- _a.sent();
- this.transitionComplete();
- return [2];
- }
- });
- });
- };
- SceneTransition.prototype.transitionComplete = function () {
- SceneManager.sceneTransition = null;
- if (this.onTransitionCompleted) {
- this.onTransitionCompleted();
- }
- };
- SceneTransition.prototype.loadNextScene = function () {
- return __awaiter(this, void 0, void 0, function () {
- var _a;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- if (this.onScreenObscured)
- this.onScreenObscured();
- if (!this.loadsNewScene) {
- this.isNewSceneLoaded = true;
- }
- _a = SceneManager;
- return [4, this.sceneLoadAction()];
- case 1:
- _a.scene = _b.sent();
- this.isNewSceneLoaded = true;
- return [2];
- }
- });
- });
- };
- SceneTransition.prototype.tickEffectProgressProperty = function (filter, duration, easeType, reverseDirection) {
- if (reverseDirection === void 0) { reverseDirection = false; }
- return new Promise(function (resolve) {
- var start = reverseDirection ? 1 : 0;
- var end = reverseDirection ? 0 : 1;
- egret.Tween.get(filter.uniforms).set({ _progress: start }).to({ _progress: end }, duration * 1000, easeType).call(function () {
- resolve();
- });
- });
- };
- return SceneTransition;
-}());
-var FadeTransition = (function (_super) {
- __extends(FadeTransition, _super);
- function FadeTransition(sceneLoadAction) {
- var _this = _super.call(this, sceneLoadAction) || this;
- _this.fadeToColor = 0x000000;
- _this.fadeOutDuration = 0.4;
- _this.fadeEaseType = egret.Ease.quadInOut;
- _this.delayBeforeFadeInDuration = 0.1;
- _this._alpha = 0;
- _this._mask = new egret.Shape();
- return _this;
- }
- FadeTransition.prototype.onBeginTransition = function () {
- return __awaiter(this, void 0, void 0, function () {
+ return this._entityDict.get(tag);
+ };
+ EntityList.prototype.addToTagList = function (entity) {
+ var list = this.getTagList(entity.tag);
+ if (!list.contains(entity)) {
+ list.push(entity);
+ this._unsortedTags.push(entity.tag);
+ }
+ };
+ EntityList.prototype.removeFromTagList = function (entity) {
+ var list = this._entityDict.get(entity.tag);
+ if (list) {
+ list.remove(entity);
+ }
+ };
+ EntityList.prototype.update = function () {
+ for (var i = 0; i < this._entities.length; i++) {
+ var entity = this._entities[i];
+ if (entity.enabled && (entity.updateInterval == 1 || es.Time.frameCount % entity.updateInterval == 0))
+ entity.update();
+ }
+ };
+ EntityList.prototype.updateLists = function () {
var _this = this;
- return __generator(this, function (_a) {
- this._mask.graphics.beginFill(this.fadeToColor, 1);
- this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
- this._mask.graphics.endFill();
- SceneManager.stage.addChild(this._mask);
- egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType)
- .call(function () { return __awaiter(_this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0: return [4, this.loadNextScene()];
- case 1:
- _a.sent();
- return [2];
- }
- });
- }); }).wait(this.delayBeforeFadeInDuration).call(function () {
- egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () {
- _this.transitionComplete();
- SceneManager.stage.removeChild(_this._mask);
- });
+ if (this._entitiesToRemove.length > 0) {
+ var temp = this._entitiesToRemove;
+ this._entitiesToRemove = this._tempEntityList;
+ this._tempEntityList = temp;
+ this._tempEntityList.forEach(function (entity) {
+ _this.removeFromTagList(entity);
+ _this._entities.remove(entity);
+ entity.onRemovedFromScene();
+ entity.scene = null;
+ _this.scene.entityProcessors.onEntityRemoved(entity);
});
- return [2];
+ this._tempEntityList.length = 0;
+ }
+ if (this._entitiesToAdded.length > 0) {
+ var temp = this._entitiesToAdded;
+ this._entitiesToAdded = this._tempEntityList;
+ this._tempEntityList = temp;
+ this._tempEntityList.forEach(function (entity) {
+ if (!_this._entities.contains(entity)) {
+ _this._entities.push(entity);
+ entity.scene = _this.scene;
+ _this.addToTagList(entity);
+ _this.scene.entityProcessors.onEntityAdded(entity);
+ }
+ });
+ this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); });
+ this._tempEntityList.length = 0;
+ this._isEntityListUnsorted = true;
+ }
+ if (this._isEntityListUnsorted) {
+ this._entities.sort();
+ this._isEntityListUnsorted = false;
+ }
+ if (this._unsortedTags.length > 0) {
+ this._unsortedTags.forEach(function (tag) {
+ _this._entityDict.get(tag).sort();
+ });
+ this._unsortedTags.length = 0;
+ }
+ };
+ EntityList.prototype.findEntity = function (name) {
+ for (var i = 0; i < this._entities.length; i++) {
+ if (this._entities[i].name == name)
+ return this._entities[i];
+ }
+ return this._entitiesToAdded.firstOrDefault(function (entity) { return entity.name == name; });
+ };
+ EntityList.prototype.entitiesWithTag = function (tag) {
+ var list = this.getTagList(tag);
+ var returnList = es.ListPool.obtain();
+ for (var i = 0; i < list.length; i++)
+ returnList.push(list[i]);
+ return returnList;
+ };
+ EntityList.prototype.entitiesOfType = function (type) {
+ var list = es.ListPool.obtain();
+ for (var i = 0; i < this._entities.length; i++) {
+ if (this._entities[i] instanceof type)
+ list.push(this._entities[i]);
+ }
+ this._entitiesToAdded.forEach(function (entity) {
+ if (entity instanceof type)
+ list.push(entity);
});
+ return list;
+ };
+ EntityList.prototype.findComponentOfType = function (type) {
+ for (var i = 0; i < this._entities.length; i++) {
+ if (this._entities[i].enabled) {
+ var comp = this._entities[i].getComponent(type);
+ if (comp)
+ return comp;
+ }
+ }
+ for (var i = 0; i < this._entitiesToAdded.length; i++) {
+ var entity = this._entitiesToAdded[i];
+ if (entity.enabled) {
+ var comp = entity.getComponent(type);
+ if (comp)
+ return comp;
+ }
+ }
+ return null;
+ };
+ EntityList.prototype.findComponentsOfType = function (type) {
+ var comps = es.ListPool.obtain();
+ for (var i = 0; i < this._entities.length; i++) {
+ if (this._entities[i].enabled)
+ this._entities[i].getComponents(type, comps);
+ }
+ for (var i = 0; i < this._entitiesToAdded.length; i++) {
+ var entity = this._entitiesToAdded[i];
+ if (entity.enabled)
+ entity.getComponents(type, comps);
+ }
+ return comps;
+ };
+ return EntityList;
+ }());
+ es.EntityList = EntityList;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var EntityProcessorList = (function () {
+ function EntityProcessorList() {
+ this._processors = [];
+ }
+ EntityProcessorList.prototype.add = function (processor) {
+ this._processors.push(processor);
+ };
+ EntityProcessorList.prototype.remove = function (processor) {
+ this._processors.remove(processor);
+ };
+ EntityProcessorList.prototype.onComponentAdded = function (entity) {
+ this.notifyEntityChanged(entity);
+ };
+ EntityProcessorList.prototype.onComponentRemoved = function (entity) {
+ this.notifyEntityChanged(entity);
+ };
+ EntityProcessorList.prototype.onEntityAdded = function (entity) {
+ this.notifyEntityChanged(entity);
+ };
+ EntityProcessorList.prototype.onEntityRemoved = function (entity) {
+ this.removeFromProcessors(entity);
+ };
+ EntityProcessorList.prototype.begin = function () {
+ };
+ EntityProcessorList.prototype.update = function () {
+ for (var i = 0; i < this._processors.length; i++) {
+ this._processors[i].update();
+ }
+ };
+ EntityProcessorList.prototype.lateUpdate = function () {
+ for (var i = 0; i < this._processors.length; i++) {
+ this._processors[i].lateUpdate();
+ }
+ };
+ EntityProcessorList.prototype.end = function () {
+ };
+ EntityProcessorList.prototype.getProcessor = function () {
+ for (var i = 0; i < this._processors.length; i++) {
+ var processor = this._processors[i];
+ if (processor instanceof es.EntitySystem)
+ return processor;
+ }
+ return null;
+ };
+ EntityProcessorList.prototype.notifyEntityChanged = function (entity) {
+ for (var i = 0; i < this._processors.length; i++) {
+ this._processors[i].onChanged(entity);
+ }
+ };
+ EntityProcessorList.prototype.removeFromProcessors = function (entity) {
+ for (var i = 0; i < this._processors.length; i++) {
+ this._processors[i].remove(entity);
+ }
+ };
+ return EntityProcessorList;
+ }());
+ es.EntityProcessorList = EntityProcessorList;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Matcher = (function () {
+ function Matcher() {
+ this.allSet = new es.BitSet();
+ this.exclusionSet = new es.BitSet();
+ this.oneSet = new es.BitSet();
+ }
+ Matcher.empty = function () {
+ return new Matcher();
+ };
+ Matcher.prototype.getAllSet = function () {
+ return this.allSet;
+ };
+ Matcher.prototype.getExclusionSet = function () {
+ return this.exclusionSet;
+ };
+ Matcher.prototype.getOneSet = function () {
+ return this.oneSet;
+ };
+ Matcher.prototype.IsIntersted = function (e) {
+ if (!this.allSet.isEmpty()) {
+ for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) {
+ if (!e.componentBits.get(i))
+ return false;
+ }
+ }
+ if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits))
+ return false;
+ if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits))
+ return false;
+ return true;
+ };
+ Matcher.prototype.all = function () {
+ var _this = this;
+ var types = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ types[_i] = arguments[_i];
+ }
+ types.forEach(function (type) {
+ _this.allSet.set(es.ComponentTypeManager.getIndexFor(type));
+ });
+ return this;
+ };
+ Matcher.prototype.exclude = function () {
+ var _this = this;
+ var types = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ types[_i] = arguments[_i];
+ }
+ types.forEach(function (type) {
+ _this.exclusionSet.set(es.ComponentTypeManager.getIndexFor(type));
+ });
+ return this;
+ };
+ Matcher.prototype.one = function () {
+ var _this = this;
+ var types = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ types[_i] = arguments[_i];
+ }
+ types.forEach(function (type) {
+ _this.oneSet.set(es.ComponentTypeManager.getIndexFor(type));
+ });
+ return this;
+ };
+ return Matcher;
+ }());
+ es.Matcher = Matcher;
+})(es || (es = {}));
+var ObjectUtils = (function () {
+ function ObjectUtils() {
+ }
+ ObjectUtils.clone = function (p, c) {
+ if (c === void 0) { c = null; }
+ var c = c || {};
+ for (var i in p) {
+ if (typeof p[i] === 'object') {
+ c[i] = p[i] instanceof Array ? [] : {};
+ this.clone(p[i], c[i]);
+ }
+ else {
+ c[i] = p[i];
+ }
+ }
+ return c;
+ };
+ return ObjectUtils;
+}());
+var es;
+(function (es) {
+ var RenderableComparer = (function () {
+ function RenderableComparer() {
+ }
+ RenderableComparer.prototype.compare = function (self, other) {
+ return other.renderLayer - self.renderLayer;
+ };
+ return RenderableComparer;
+ }());
+ es.RenderableComparer = RenderableComparer;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var RenderableComponentList = (function () {
+ function RenderableComponentList() {
+ this._components = [];
+ this._componentsByRenderLayer = new Map();
+ this._unsortedRenderLayers = [];
+ this._componentsNeedSort = true;
+ }
+ Object.defineProperty(RenderableComponentList.prototype, "count", {
+ get: function () {
+ return this._components.length;
+ },
+ enumerable: true,
+ configurable: true
});
+ Object.defineProperty(RenderableComponentList.prototype, "buffer", {
+ get: function () {
+ return this._components;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ RenderableComponentList.prototype.add = function (component) {
+ this._components.push(component);
+ this.addToRenderLayerList(component, component.renderLayer);
+ };
+ RenderableComponentList.prototype.remove = function (component) {
+ this._components.remove(component);
+ this._componentsByRenderLayer.get(component.renderLayer).remove(component);
+ };
+ RenderableComponentList.prototype.updateRenderableRenderLayer = function (component, oldRenderLayer, newRenderLayer) {
+ if (this._componentsByRenderLayer.has(oldRenderLayer) && this._componentsByRenderLayer.get(oldRenderLayer).contains(component)) {
+ this._componentsByRenderLayer.get(oldRenderLayer).remove(component);
+ this.addToRenderLayerList(component, newRenderLayer);
+ }
+ };
+ RenderableComponentList.prototype.setRenderLayerNeedsComponentSort = function (renderLayer) {
+ if (!this._unsortedRenderLayers.contains(renderLayer))
+ this._unsortedRenderLayers.push(renderLayer);
+ this._componentsNeedSort = true;
+ };
+ RenderableComponentList.prototype.setNeedsComponentSort = function () {
+ this._componentsNeedSort = true;
+ };
+ RenderableComponentList.prototype.addToRenderLayerList = function (component, renderLayer) {
+ var list = this.componentsWithRenderLayer(renderLayer);
+ if (!list.contains(component)) {
+ console.warn("Component renderLayer list already contains this component");
+ return;
+ }
+ list.push(component);
+ if (!this._unsortedRenderLayers.contains(renderLayer))
+ this._unsortedRenderLayers.push(renderLayer);
+ this._componentsNeedSort = true;
+ };
+ RenderableComponentList.prototype.componentsWithRenderLayer = function (renderLayer) {
+ if (!this._componentsByRenderLayer.get(renderLayer)) {
+ this._componentsByRenderLayer.set(renderLayer, []);
+ }
+ return this._componentsByRenderLayer.get(renderLayer);
+ };
+ RenderableComponentList.prototype.updateList = function () {
+ if (this._componentsNeedSort) {
+ this._components.sort(RenderableComponentList.compareUpdatableOrder.compare);
+ this._componentsNeedSort = false;
+ }
+ if (this._unsortedRenderLayers.length > 0) {
+ for (var i = 0, count = this._unsortedRenderLayers.length; i < count; i++) {
+ var renderLayerComponents = this._componentsByRenderLayer.get(this._unsortedRenderLayers[i]);
+ if (renderLayerComponents) {
+ renderLayerComponents.sort(RenderableComponentList.compareUpdatableOrder.compare);
+ }
+ }
+ this._unsortedRenderLayers.length = 0;
+ }
+ };
+ RenderableComponentList.compareUpdatableOrder = new es.RenderableComparer();
+ return RenderableComponentList;
+ }());
+ es.RenderableComponentList = RenderableComponentList;
+})(es || (es = {}));
+var StringUtils = (function () {
+ function StringUtils() {
+ }
+ StringUtils.matchChineseWord = function (str) {
+ var patternA = /[\u4E00-\u9FA5]+/gim;
+ return str.match(patternA);
};
- FadeTransition.prototype.render = function () {
- this._mask.graphics.clear();
- this._mask.graphics.beginFill(this.fadeToColor, this._alpha);
- this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
- this._mask.graphics.endFill();
+ StringUtils.lTrim = function (target) {
+ var startIndex = 0;
+ while (this.isWhiteSpace(target.charAt(startIndex))) {
+ startIndex++;
+ }
+ return target.slice(startIndex, target.length);
};
- return FadeTransition;
-}(SceneTransition));
-var WindTransition = (function (_super) {
- __extends(WindTransition, _super);
- function WindTransition(sceneLoadAction) {
- var _this = _super.call(this, sceneLoadAction) || this;
- _this.duration = 1;
- _this.easeType = egret.Ease.quadOut;
- var vertexSrc = "attribute vec2 aVertexPosition;\n" +
+ StringUtils.rTrim = function (target) {
+ var endIndex = target.length - 1;
+ while (this.isWhiteSpace(target.charAt(endIndex))) {
+ endIndex--;
+ }
+ return target.slice(0, endIndex + 1);
+ };
+ StringUtils.trim = function (target) {
+ if (target == null) {
+ return null;
+ }
+ return this.rTrim(this.lTrim(target));
+ };
+ StringUtils.isWhiteSpace = function (str) {
+ if (str == " " || str == "\t" || str == "\r" || str == "\n")
+ return true;
+ return false;
+ };
+ StringUtils.replaceMatch = function (mainStr, targetStr, replaceStr, caseMark) {
+ if (caseMark === void 0) { caseMark = false; }
+ var len = mainStr.length;
+ var tempStr = "";
+ var isMatch = false;
+ var tempTarget = caseMark == true ? targetStr.toLowerCase() : targetStr;
+ for (var i = 0; i < len; i++) {
+ isMatch = false;
+ if (mainStr.charAt(i) == tempTarget.charAt(0)) {
+ if (mainStr.substr(i, tempTarget.length) == tempTarget) {
+ isMatch = true;
+ }
+ }
+ if (isMatch) {
+ tempStr += replaceStr;
+ i = i + tempTarget.length - 1;
+ }
+ else {
+ tempStr += mainStr.charAt(i);
+ }
+ }
+ return tempStr;
+ };
+ StringUtils.htmlSpecialChars = function (str, reversion) {
+ if (reversion === void 0) { reversion = false; }
+ var len = this.specialSigns.length;
+ for (var i = 0; i < len; i += 2) {
+ var from = void 0;
+ var to = void 0;
+ from = this.specialSigns[i];
+ to = this.specialSigns[i + 1];
+ if (reversion) {
+ var temp = from;
+ from = to;
+ to = temp;
+ }
+ str = this.replaceMatch(str, from, to);
+ }
+ return str;
+ };
+ StringUtils.zfill = function (str, width) {
+ if (width === void 0) { width = 2; }
+ if (!str) {
+ return str;
+ }
+ width = Math.floor(width);
+ var slen = str.length;
+ if (slen >= width) {
+ return str;
+ }
+ var negative = false;
+ if (str.substr(0, 1) == '-') {
+ negative = true;
+ str = str.substr(1);
+ }
+ var len = width - slen;
+ for (var i = 0; i < len; i++) {
+ str = '0' + str;
+ }
+ if (negative) {
+ str = '-' + str;
+ }
+ return str;
+ };
+ StringUtils.reverse = function (str) {
+ if (str.length > 1)
+ return this.reverse(str.substring(1)) + str.substring(0, 1);
+ else
+ return str;
+ };
+ StringUtils.cutOff = function (str, start, len, order) {
+ if (order === void 0) { order = true; }
+ start = Math.floor(start);
+ len = Math.floor(len);
+ var length = str.length;
+ if (start > length)
+ start = length;
+ var s = start;
+ var e = start + len;
+ var newStr;
+ if (order) {
+ newStr = str.substring(0, s) + str.substr(e, length);
+ }
+ else {
+ s = length - 1 - start - len;
+ e = s + len;
+ newStr = str.substring(0, s + 1) + str.substr(e + 1, length);
+ }
+ return newStr;
+ };
+ StringUtils.strReplace = function (str, rStr) {
+ var i = 0, len = rStr.length;
+ for (; i < len; i++) {
+ if (rStr[i] == null || rStr[i] == "") {
+ rStr[i] = "无";
+ }
+ str = str.replace("{" + i + "}", rStr[i]);
+ }
+ return str;
+ };
+ StringUtils.specialSigns = [
+ '&', '&',
+ '<', '<',
+ '>', '>',
+ '"', '"',
+ "'", ''',
+ '®', '®',
+ '©', '©',
+ '™', '™',
+ ];
+ return StringUtils;
+}());
+var es;
+(function (es) {
+ var TextureUtils = (function () {
+ function TextureUtils() {
+ }
+ TextureUtils.convertImageToCanvas = function (texture, rect) {
+ if (!this.sharedCanvas) {
+ this.sharedCanvas = egret.sys.createCanvas();
+ this.sharedContext = this.sharedCanvas.getContext("2d");
+ }
+ var w = texture.$getTextureWidth();
+ var h = texture.$getTextureHeight();
+ if (!rect) {
+ rect = egret.$TempRectangle;
+ rect.x = 0;
+ rect.y = 0;
+ rect.width = w;
+ rect.height = h;
+ }
+ rect.x = Math.min(rect.x, w - 1);
+ rect.y = Math.min(rect.y, h - 1);
+ rect.width = Math.min(rect.width, w - rect.x);
+ rect.height = Math.min(rect.height, h - rect.y);
+ var iWidth = Math.floor(rect.width);
+ var iHeight = Math.floor(rect.height);
+ var surface = this.sharedCanvas;
+ surface["style"]["width"] = iWidth + "px";
+ surface["style"]["height"] = iHeight + "px";
+ this.sharedCanvas.width = iWidth;
+ this.sharedCanvas.height = iHeight;
+ if (egret.Capabilities.renderMode == "webgl") {
+ var renderTexture = void 0;
+ if (!texture.$renderBuffer) {
+ if (egret.sys.systemRenderer["renderClear"]) {
+ egret.sys.systemRenderer["renderClear"]();
+ }
+ renderTexture = new egret.RenderTexture();
+ renderTexture.drawToTexture(new egret.Bitmap(texture));
+ }
+ else {
+ renderTexture = texture;
+ }
+ var pixels = renderTexture.$renderBuffer.getPixels(rect.x, rect.y, iWidth, iHeight);
+ var x = 0;
+ var y = 0;
+ for (var i = 0; i < pixels.length; i += 4) {
+ this.sharedContext.fillStyle =
+ 'rgba(' + pixels[i]
+ + ',' + pixels[i + 1]
+ + ',' + pixels[i + 2]
+ + ',' + (pixels[i + 3] / 255) + ')';
+ this.sharedContext.fillRect(x, y, 1, 1);
+ x++;
+ if (x == iWidth) {
+ x = 0;
+ y++;
+ }
+ }
+ if (!texture.$renderBuffer) {
+ renderTexture.dispose();
+ }
+ return surface;
+ }
+ else {
+ var bitmapData = texture;
+ var offsetX = Math.round(bitmapData.$offsetX);
+ var offsetY = Math.round(bitmapData.$offsetY);
+ var bitmapWidth = bitmapData.$bitmapWidth;
+ var bitmapHeight = bitmapData.$bitmapHeight;
+ var $TextureScaleFactor = es.Core._instance.stage.textureScaleFactor;
+ this.sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / $TextureScaleFactor, bitmapData.$bitmapY + rect.y / $TextureScaleFactor, bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height);
+ return surface;
+ }
+ };
+ TextureUtils.toDataURL = function (type, texture, rect, encoderOptions) {
+ try {
+ var surface = this.convertImageToCanvas(texture, rect);
+ var result = surface.toDataURL(type, encoderOptions);
+ return result;
+ }
+ catch (e) {
+ egret.$error(1033);
+ }
+ return null;
+ };
+ TextureUtils.eliFoTevas = function (type, texture, filePath, rect, encoderOptions) {
+ var surface = this.convertImageToCanvas(texture, rect);
+ var result = surface.toTempFilePathSync({
+ fileType: type.indexOf("png") >= 0 ? "png" : "jpg"
+ });
+ wx.getFileSystemManager().saveFile({
+ tempFilePath: result,
+ filePath: wx.env.USER_DATA_PATH + "/" + filePath,
+ success: function (res) {
+ }
+ });
+ return result;
+ };
+ TextureUtils.getPixel32 = function (texture, x, y) {
+ egret.$warn(1041, "getPixel32", "getPixels");
+ return texture.getPixels(x, y);
+ };
+ TextureUtils.getPixels = function (texture, x, y, width, height) {
+ if (width === void 0) { width = 1; }
+ if (height === void 0) { height = 1; }
+ if (egret.Capabilities.renderMode == "webgl") {
+ var renderTexture = void 0;
+ if (!texture.$renderBuffer) {
+ renderTexture = new egret.RenderTexture();
+ renderTexture.drawToTexture(new egret.Bitmap(texture));
+ }
+ else {
+ renderTexture = texture;
+ }
+ var pixels = renderTexture.$renderBuffer.getPixels(x, y, width, height);
+ return pixels;
+ }
+ try {
+ var surface = this.convertImageToCanvas(texture);
+ var result = this.sharedContext.getImageData(x, y, width, height).data;
+ return result;
+ }
+ catch (e) {
+ egret.$error(1039);
+ }
+ };
+ return TextureUtils;
+ }());
+ es.TextureUtils = TextureUtils;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Time = (function () {
+ function Time() {
+ }
+ Time.update = function (currentTime) {
+ var dt = (currentTime - this._lastTime) / 1000;
+ this.deltaTime = dt * this.timeScale;
+ this.unscaledDeltaTime = dt;
+ this._timeSinceSceneLoad += dt;
+ this.frameCount++;
+ this._lastTime = currentTime;
+ };
+ Time.sceneChanged = function () {
+ this._timeSinceSceneLoad = 0;
+ };
+ Time.checkEvery = function (interval) {
+ return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval);
+ };
+ Time.deltaTime = 0;
+ Time.timeScale = 1;
+ Time.frameCount = 0;
+ Time._lastTime = 0;
+ return Time;
+ }());
+ es.Time = Time;
+})(es || (es = {}));
+var TimeUtils = (function () {
+ function TimeUtils() {
+ }
+ TimeUtils.monthId = function (d) {
+ if (d === void 0) { d = null; }
+ d = d ? d : new Date();
+ var y = d.getFullYear();
+ var m = d.getMonth() + 1;
+ var g = m < 10 ? "0" : "";
+ return parseInt(y + g + m);
+ };
+ TimeUtils.dateId = function (t) {
+ if (t === void 0) { t = null; }
+ t = t ? t : new Date();
+ var m = t.getMonth() + 1;
+ var a = m < 10 ? "0" : "";
+ var d = t.getDate();
+ var b = d < 10 ? "0" : "";
+ return parseInt(t.getFullYear() + a + m + b + d);
+ };
+ TimeUtils.weekId = function (d, first) {
+ if (d === void 0) { d = null; }
+ if (first === void 0) { first = true; }
+ d = d ? d : new Date();
+ var c = new Date();
+ c.setTime(d.getTime());
+ c.setDate(1);
+ c.setMonth(0);
+ var year = c.getFullYear();
+ var firstDay = c.getDay();
+ if (firstDay == 0) {
+ firstDay = 7;
+ }
+ var max = false;
+ if (firstDay <= 4) {
+ max = firstDay > 1;
+ c.setDate(c.getDate() - (firstDay - 1));
+ }
+ else {
+ c.setDate(c.getDate() + 7 - firstDay + 1);
+ }
+ var num = this.diffDay(d, c, false);
+ if (num < 0) {
+ c.setDate(1);
+ c.setMonth(0);
+ c.setDate(c.getDate() - 1);
+ return this.weekId(c, false);
+ }
+ var week = num / 7;
+ var weekIdx = Math.floor(week) + 1;
+ if (weekIdx == 53) {
+ c.setTime(d.getTime());
+ c.setDate(c.getDate() - 1);
+ var endDay = c.getDay();
+ if (endDay == 0) {
+ endDay = 7;
+ }
+ if (first && (!max || endDay < 4)) {
+ c.setFullYear(c.getFullYear() + 1);
+ c.setDate(1);
+ c.setMonth(0);
+ return this.weekId(c, false);
+ }
+ }
+ var g = weekIdx > 9 ? "" : "0";
+ var s = year + "00" + g + weekIdx;
+ return parseInt(s);
+ };
+ TimeUtils.diffDay = function (a, b, fixOne) {
+ if (fixOne === void 0) { fixOne = false; }
+ var x = (a.getTime() - b.getTime()) / 86400000;
+ return fixOne ? Math.ceil(x) : Math.floor(x);
+ };
+ TimeUtils.getFirstDayOfWeek = function (d) {
+ d = d ? d : new Date();
+ var day = d.getDay() || 7;
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1 - day, 0, 0, 0, 0);
+ };
+ TimeUtils.getFirstOfDay = function (d) {
+ d = d ? d : new Date();
+ d.setHours(0, 0, 0, 0);
+ return d;
+ };
+ TimeUtils.getNextFirstOfDay = function (d) {
+ return new Date(this.getFirstOfDay(d).getTime() + 86400000);
+ };
+ TimeUtils.formatDate = function (date) {
+ var y = date.getFullYear();
+ var m = date.getMonth() + 1;
+ m = m < 10 ? '0' + m : m;
+ var d = date.getDate();
+ d = d < 10 ? ('0' + d) : d;
+ return y + '-' + m + '-' + d;
+ };
+ TimeUtils.formatDateTime = function (date) {
+ var y = date.getFullYear();
+ var m = date.getMonth() + 1;
+ m = m < 10 ? ('0' + m) : m;
+ var d = date.getDate();
+ d = d < 10 ? ('0' + d) : d;
+ var h = date.getHours();
+ var i = date.getMinutes();
+ i = i < 10 ? ('0' + i) : i;
+ var s = date.getSeconds();
+ s = s < 10 ? ('0' + s) : s;
+ return y + '-' + m + '-' + d + ' ' + h + ':' + i + ":" + s;
+ };
+ TimeUtils.parseDate = function (s) {
+ var t = Date.parse(s);
+ if (!isNaN(t)) {
+ return new Date(Date.parse(s.replace(/-/g, "/")));
+ }
+ else {
+ return new Date();
+ }
+ };
+ TimeUtils.secondToTime = function (time, partition, showHour) {
+ if (time === void 0) { time = 0; }
+ if (partition === void 0) { partition = ":"; }
+ if (showHour === void 0) { showHour = true; }
+ var hours = Math.floor(time / 3600);
+ var minutes = Math.floor(time % 3600 / 60);
+ var seconds = Math.floor(time % 3600 % 60);
+ var h = hours.toString();
+ var m = minutes.toString();
+ var s = seconds.toString();
+ if (hours < 10)
+ h = "0" + h;
+ if (minutes < 10)
+ m = "0" + m;
+ if (seconds < 10)
+ s = "0" + s;
+ var timeStr;
+ if (showHour)
+ timeStr = h + partition + m + partition + s;
+ else
+ timeStr = m + partition + s;
+ return timeStr;
+ };
+ TimeUtils.timeToMillisecond = function (time, partition) {
+ if (partition === void 0) { partition = ":"; }
+ var _ary = time.split(partition);
+ var timeNum = 0;
+ var len = _ary.length;
+ for (var i = 0; i < len; i++) {
+ var n = _ary[i];
+ timeNum += n * Math.pow(60, (len - 1 - i));
+ }
+ timeNum *= 1000;
+ return timeNum.toString();
+ };
+ return TimeUtils;
+}());
+var es;
+(function (es) {
+ var GraphicsCapabilities = (function (_super) {
+ __extends(GraphicsCapabilities, _super);
+ function GraphicsCapabilities() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ GraphicsCapabilities.prototype.initialize = function (device) {
+ this.platformInitialize(device);
+ };
+ GraphicsCapabilities.prototype.platformInitialize = function (device) {
+ if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME)
+ return;
+ var capabilities = this;
+ capabilities["isMobile"] = true;
+ var systemInfo = wx.getSystemInfoSync();
+ var systemStr = systemInfo.system.toLowerCase();
+ if (systemStr.indexOf("ios") > -1) {
+ capabilities["os"] = "iOS";
+ }
+ else if (systemStr.indexOf("android") > -1) {
+ capabilities["os"] = "Android";
+ }
+ var language = systemInfo.language;
+ if (language.indexOf('zh') > -1) {
+ language = "zh-CN";
+ }
+ else {
+ language = "en-US";
+ }
+ capabilities["language"] = language;
+ };
+ return GraphicsCapabilities;
+ }(egret.Capabilities));
+ es.GraphicsCapabilities = GraphicsCapabilities;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var GraphicsDevice = (function () {
+ function GraphicsDevice() {
+ this.setup();
+ this.graphicsCapabilities = new es.GraphicsCapabilities();
+ this.graphicsCapabilities.initialize(this);
+ }
+ Object.defineProperty(GraphicsDevice.prototype, "viewport", {
+ get: function () {
+ return this._viewport;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ GraphicsDevice.prototype.setup = function () {
+ this._viewport = new es.Viewport(0, 0, es.Core._instance.stage.stageWidth, es.Core._instance.stage.stageHeight);
+ };
+ return GraphicsDevice;
+ }());
+ es.GraphicsDevice = GraphicsDevice;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Viewport = (function () {
+ function Viewport(x, y, width, height) {
+ this._x = x;
+ this._y = y;
+ this._width = width;
+ this._height = height;
+ this._minDepth = 0;
+ this._maxDepth = 1;
+ }
+ Object.defineProperty(Viewport.prototype, "width", {
+ get: function () {
+ return this._width;
+ },
+ set: function (value) {
+ this._width = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Viewport.prototype, "height", {
+ get: function () {
+ return this._height;
+ },
+ set: function (value) {
+ this._height = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Viewport.prototype, "aspectRatio", {
+ get: function () {
+ if ((this._height != 0) && (this._width != 0))
+ return (this._width / this._height);
+ return 0;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Viewport.prototype, "bounds", {
+ get: function () {
+ return new es.Rectangle(this._x, this._y, this._width, this._height);
+ },
+ set: function (value) {
+ this._x = value.x;
+ this._y = value.y;
+ this._width = value.width;
+ this._height = value.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Viewport;
+ }());
+ es.Viewport = Viewport;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var GaussianBlurEffect = (function (_super) {
+ __extends(GaussianBlurEffect, _super);
+ function GaussianBlurEffect() {
+ return _super.call(this, es.PostProcessor.default_vert, GaussianBlurEffect.blur_frag, {
+ screenWidth: es.Core.graphicsDevice.viewport.width,
+ screenHeight: es.Core.graphicsDevice.viewport.height
+ }) || this;
+ }
+ GaussianBlurEffect.blur_frag = "precision mediump float;\n" +
+ "uniform sampler2D uSampler;\n" +
+ "uniform float screenWidth;\n" +
+ "uniform float screenHeight;\n" +
+ "float normpdf(in float x, in float sigma)\n" +
+ "{\n" +
+ "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" +
+ "}\n" +
+ "void main()\n" +
+ "{\n" +
+ "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" +
+ "const int mSize = 11;\n" +
+ "const int kSize = (mSize - 1)/2;\n" +
+ "float kernel[mSize];\n" +
+ "vec3 final_colour = vec3(0.0);\n" +
+ "float sigma = 7.0;\n" +
+ "float z = 0.0;\n" +
+ "for (int j = 0; j <= kSize; ++j)\n" +
+ "{\n" +
+ "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" +
+ "}\n" +
+ "for (int j = 0; j < mSize; ++j)\n" +
+ "{\n" +
+ "z += kernel[j];\n" +
+ "}\n" +
+ "for (int i = -kSize; i <= kSize; ++i)\n" +
+ "{\n" +
+ "for (int j = -kSize; j <= kSize; ++j)\n" +
+ "{\n" +
+ "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" +
+ "}\n}\n" +
+ "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" +
+ "}";
+ return GaussianBlurEffect;
+ }(egret.CustomFilter));
+ es.GaussianBlurEffect = GaussianBlurEffect;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var PolygonLightEffect = (function (_super) {
+ __extends(PolygonLightEffect, _super);
+ function PolygonLightEffect() {
+ return _super.call(this, PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc) || this;
+ }
+ PolygonLightEffect.vertSrc = "attribute vec2 aVertexPosition;\n" +
"attribute vec2 aTextureCoord;\n" +
"uniform vec2 projectionVector;\n" +
"varying vec2 vTextureCoord;\n" +
@@ -3236,1745 +4918,3745 @@ var WindTransition = (function (_super) {
" gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
" vTextureCoord = aTextureCoord;\n" +
"}";
- var fragmentSrc = "precision lowp float;\n" +
+ PolygonLightEffect.fragmentSrc = "precision lowp float;\n" +
"varying vec2 vTextureCoord;\n" +
"uniform sampler2D uSampler;\n" +
- "uniform float _progress;\n" +
- "uniform float _size;\n" +
- "uniform float _windSegments;\n" +
+ "#define SAMPLE_COUNT 15\n" +
+ "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" +
+ "uniform float _sampleWeights[SAMPLE_COUNT];\n" +
"void main(void) {\n" +
- "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" +
- "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" +
- "float r = x - floor(x);\n" +
- "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" +
- "vec4 fg = texture2D(uSampler, vTextureCoord);\n" +
- "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" +
+ "vec4 c = vec4(0, 0, 0, 0);\n" +
+ "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" +
+ " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" +
+ "gl_FragColor = c;\n" +
"}";
- _this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, {
- _progress: 0,
- _size: 0.3,
- _windSegments: 100
- });
- _this._mask = new egret.Shape();
- _this._mask.graphics.beginFill(0xFFFFFF, 1);
- _this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
- _this._mask.graphics.endFill();
- _this._mask.filters = [_this._windEffect];
- SceneManager.stage.addChild(_this._mask);
- return _this;
- }
- Object.defineProperty(WindTransition.prototype, "windSegments", {
- set: function (value) {
- this._windEffect.uniforms._windSegments = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(WindTransition.prototype, "size", {
- set: function (value) {
- this._windEffect.uniforms._size = value;
- },
- enumerable: true,
- configurable: true
- });
- WindTransition.prototype.onBeginTransition = function () {
- return __awaiter(this, void 0, void 0, function () {
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- this.loadNextScene();
- return [4, this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType)];
- case 1:
- _a.sent();
- this.transitionComplete();
- SceneManager.stage.removeChild(this._mask);
- return [2];
- }
- });
- });
- };
- return WindTransition;
-}(SceneTransition));
-var Flags = (function () {
- function Flags() {
- }
- Flags.isFlagSet = function (self, flag) {
- return (self & flag) != 0;
- };
- Flags.isUnshiftedFlagSet = function (self, flag) {
- flag = 1 << flag;
- return (self & flag) != 0;
- };
- Flags.setFlagExclusive = function (self, flag) {
- return 1 << flag;
- };
- Flags.setFlag = function (self, flag) {
- return (self | 1 << flag);
- };
- Flags.unsetFlag = function (self, flag) {
- flag = 1 << flag;
- return (self & (~flag));
- };
- Flags.invertFlags = function (self) {
- return ~self;
- };
- return Flags;
-}());
-var MathHelper = (function () {
- function MathHelper() {
- }
- MathHelper.toDegrees = function (radians) {
- return radians * 57.295779513082320876798154814105;
- };
- MathHelper.toRadians = function (degrees) {
- return degrees * 0.017453292519943295769236907684886;
- };
- MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) {
- return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin);
- };
- MathHelper.lerp = function (value1, value2, amount) {
- return value1 + (value2 - value1) * amount;
- };
- MathHelper.clamp = function (value, min, max) {
- if (value < min)
- return min;
- if (value > max)
- return max;
- return value;
- };
- MathHelper.pointOnCirlce = function (circleCenter, radius, angleInDegrees) {
- var radians = MathHelper.toRadians(angleInDegrees);
- return new Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y);
- };
- MathHelper.isEven = function (value) {
- return value % 2 == 0;
- };
- MathHelper.Epsilon = 0.00001;
- MathHelper.Rad2Deg = 57.29578;
- MathHelper.Deg2Rad = 0.0174532924;
- return MathHelper;
-}());
-var Matrix2D = (function () {
- function Matrix2D(m11, m12, m21, m22, m31, m32) {
- this.m11 = 0;
- this.m12 = 0;
- this.m21 = 0;
- this.m22 = 0;
- this.m31 = 0;
- this.m32 = 0;
- this.m11 = m11 ? m11 : 1;
- this.m12 = m12 ? m12 : 0;
- this.m21 = m21 ? m21 : 0;
- this.m22 = m22 ? m22 : 1;
- this.m31 = m31 ? m31 : 0;
- this.m32 = m32 ? m32 : 0;
- }
- Object.defineProperty(Matrix2D, "identity", {
- get: function () {
- return Matrix2D._identity;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Matrix2D.prototype, "translation", {
- get: function () {
- return new Vector2(this.m31, this.m32);
- },
- set: function (value) {
- this.m31 = value.x;
- this.m32 = value.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Matrix2D.prototype, "rotation", {
- get: function () {
- return Math.atan2(this.m21, this.m11);
- },
- set: function (value) {
- var val1 = Math.cos(value);
- var val2 = Math.sin(value);
- this.m11 = val1;
- this.m12 = val2;
- this.m21 = -val2;
- this.m22 = val1;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Matrix2D.prototype, "rotationDegrees", {
- get: function () {
- return MathHelper.toDegrees(this.rotation);
- },
- set: function (value) {
- this.rotation = MathHelper.toRadians(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Matrix2D.prototype, "scale", {
- get: function () {
- return new Vector2(this.m11, this.m22);
- },
- set: function (value) {
- this.m11 = value.x;
- this.m12 = value.y;
- },
- enumerable: true,
- configurable: true
- });
- Matrix2D.add = function (matrix1, matrix2) {
- matrix1.m11 += matrix2.m11;
- matrix1.m12 += matrix2.m12;
- matrix1.m21 += matrix2.m21;
- matrix1.m22 += matrix2.m22;
- matrix1.m31 += matrix2.m31;
- matrix1.m32 += matrix2.m32;
- return matrix1;
- };
- Matrix2D.divide = function (matrix1, matrix2) {
- matrix1.m11 /= matrix2.m11;
- matrix1.m12 /= matrix2.m12;
- matrix1.m21 /= matrix2.m21;
- matrix1.m22 /= matrix2.m22;
- matrix1.m31 /= matrix2.m31;
- matrix1.m32 /= matrix2.m32;
- return matrix1;
- };
- Matrix2D.multiply = function (matrix1, matrix2) {
- var result = new Matrix2D();
- var m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21);
- var m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22);
- var m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21);
- var m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22);
- var m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31;
- var m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32;
- result.m11 = m11;
- result.m12 = m12;
- result.m21 = m21;
- result.m22 = m22;
- result.m31 = m31;
- result.m32 = m32;
- return result;
- };
- Matrix2D.multiplyTranslation = function (matrix, x, y) {
- var trans = Matrix2D.createTranslation(x, y);
- return Matrix2D.multiply(matrix, trans);
- };
- Matrix2D.prototype.determinant = function () {
- return this.m11 * this.m22 - this.m12 * this.m21;
- };
- Matrix2D.invert = function (matrix, result) {
- if (result === void 0) { result = new Matrix2D(); }
- var det = 1 / matrix.determinant();
- result.m11 = matrix.m22 * det;
- result.m12 = -matrix.m12 * det;
- result.m21 = -matrix.m21 * det;
- result.m22 = matrix.m11 * det;
- result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det;
- result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det;
- return result;
- };
- Matrix2D.createTranslation = function (xPosition, yPosition) {
- var result = new Matrix2D();
- result.m11 = 1;
- result.m12 = 0;
- result.m21 = 0;
- result.m22 = 1;
- result.m31 = xPosition;
- result.m32 = yPosition;
- return result;
- };
- Matrix2D.createTranslationVector = function (position) {
- return this.createTranslation(position.x, position.y);
- };
- Matrix2D.createRotation = function (radians, result) {
- result = new Matrix2D();
- var val1 = Math.cos(radians);
- var val2 = Math.sin(radians);
- result.m11 = val1;
- result.m12 = val2;
- result.m21 = -val2;
- result.m22 = val1;
- return result;
- };
- Matrix2D.createScale = function (xScale, yScale, result) {
- if (result === void 0) { result = new Matrix2D(); }
- result.m11 = xScale;
- result.m12 = 0;
- result.m21 = 0;
- result.m22 = yScale;
- result.m31 = 0;
- result.m32 = 0;
- return result;
- };
- Matrix2D.prototype.toEgretMatrix = function () {
- var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32);
- return matrix;
- };
- Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0);
- return Matrix2D;
-}());
-var Rectangle = (function (_super) {
- __extends(Rectangle, _super);
- function Rectangle() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Object.defineProperty(Rectangle.prototype, "max", {
- get: function () {
- return new Vector2(this.right, this.bottom);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "center", {
- get: function () {
- return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2));
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "location", {
- get: function () {
- return new Vector2(this.x, this.y);
- },
- set: function (value) {
- this.x = value.x;
- this.y = value.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "size", {
- get: function () {
- return new Vector2(this.width, this.height);
- },
- set: function (value) {
- this.width = value.x;
- this.height = value.y;
- },
- enumerable: true,
- configurable: true
- });
- Rectangle.prototype.intersects = function (value) {
- return value.left < this.right &&
- this.left < value.right &&
- value.top < this.bottom &&
- this.top < value.bottom;
- };
- Rectangle.prototype.containsInVec = function (value) {
- return ((((this.x <= value.x) && (value.x < (this.x + this.width))) &&
- (this.y <= value.y)) &&
- (value.y < (this.y + this.height)));
- };
- Rectangle.prototype.containsRect = function (value) {
- return ((((this.x <= value.x) && (value.x < (this.x + this.width))) &&
- (this.y <= value.y)) &&
- (value.y < (this.y + this.height)));
- };
- Rectangle.prototype.getHalfSize = function () {
- return new Vector2(this.width * 0.5, this.height * 0.5);
- };
- Rectangle.fromMinMax = function (minX, minY, maxX, maxY) {
- return new Rectangle(minX, minY, maxX - minX, maxY - minY);
- };
- Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) {
- var edgeNormal = Vector2.zero;
- var res = new Vector2();
- res.x = MathHelper.clamp(point.x, this.left, this.right);
- res.y = MathHelper.clamp(point.y, this.top, this.bottom);
- if (this.containsInVec(res)) {
- var dl = res.x - this.left;
- var dr = this.right - res.x;
- var dt = res.y - this.top;
- var db = this.bottom - res.y;
- var min = Math.min(dl, dr, dt, db);
- if (min == dt) {
- res.y = this.top;
- edgeNormal.y = -1;
- }
- else if (min == db) {
- res.y = this.bottom;
- edgeNormal.y = 1;
- }
- else if (min == dl) {
- res.x = this.left;
- edgeNormal.x = -1;
- }
- else {
- res.x = this.right;
- edgeNormal.x = 1;
- }
+ return PolygonLightEffect;
+ }(egret.CustomFilter));
+ es.PolygonLightEffect = PolygonLightEffect;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var PostProcessor = (function () {
+ function PostProcessor(effect) {
+ if (effect === void 0) { effect = null; }
+ this.enabled = true;
+ this.effect = effect;
}
- else {
- if (res.x == this.left)
- edgeNormal.x = -1;
- if (res.x == this.right)
- edgeNormal.x = 1;
- if (res.y == this.top)
- edgeNormal.y = -1;
- if (res.y == this.bottom)
- edgeNormal.y = 1;
- }
- return { res: res, edgeNormal: edgeNormal };
- };
- Rectangle.prototype.getClosestPointOnBoundsToOrigin = function () {
- var max = this.max;
- var minDist = Math.abs(this.location.x);
- var boundsPoint = new Vector2(this.location.x, 0);
- if (Math.abs(max.x) < minDist) {
- minDist = Math.abs(max.x);
- boundsPoint.x = max.x;
- boundsPoint.y = 0;
- }
- if (Math.abs(max.y) < minDist) {
- minDist = Math.abs(max.y);
- boundsPoint.x = 0;
- boundsPoint.y = max.y;
- }
- if (Math.abs(this.location.y) < minDist) {
- minDist = Math.abs(this.location.y);
- boundsPoint.x = 0;
- boundsPoint.y = this.location.y;
- }
- return boundsPoint;
- };
- Rectangle.rectEncompassingPoints = function (points) {
- var minX = Number.POSITIVE_INFINITY;
- var minY = Number.POSITIVE_INFINITY;
- var maxX = Number.NEGATIVE_INFINITY;
- var maxY = Number.NEGATIVE_INFINITY;
- for (var i = 0; i < points.length; i++) {
- var pt = points[i];
- if (pt.x < minX)
- minX = pt.x;
- if (pt.x > maxX)
- maxX = pt.x;
- if (pt.y < minY)
- minY = pt.y;
- if (pt.y > maxY)
- maxY = pt.y;
- }
- return this.fromMinMax(minX, minY, maxX, maxY);
- };
- return Rectangle;
-}(egret.Rectangle));
-var Vector3 = (function () {
- function Vector3(x, y, z) {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- return Vector3;
-}());
-var ColliderTriggerHelper = (function () {
- function ColliderTriggerHelper(entity) {
- this._activeTriggerIntersections = [];
- this._previousTriggerIntersections = [];
- this._tempTriggerList = [];
- this._entity = entity;
- }
- ColliderTriggerHelper.prototype.update = function () {
- var colliders = this._entity.getComponents(Collider);
- for (var i = 0; i < colliders.length; i++) {
- var collider = colliders[i];
- var boxcastResult = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers);
- collider.bounds = boxcastResult.rect;
- var neighbors = boxcastResult.colliders;
- var _loop_5 = function (j) {
- var neighbor = neighbors[j];
- if (!collider.isTrigger && !neighbor.isTrigger)
- return "continue";
- if (collider.overlaps(neighbor)) {
- var pair_1 = new Pair(collider, neighbor);
- var shouldReportTriggerEvent = this_1._activeTriggerIntersections.findIndex(function (value) {
- return value.first == pair_1.first && value.second == pair_1.second;
- }) == -1 && this_1._previousTriggerIntersections.findIndex(function (value) {
- return value.first == pair_1.first && value.second == pair_1.second;
- }) == -1;
- if (shouldReportTriggerEvent)
- this_1.notifyTriggerListeners(pair_1, true);
- if (!this_1._activeTriggerIntersections.contains(pair_1))
- this_1._activeTriggerIntersections.push(pair_1);
- }
- };
- var this_1 = this;
- for (var j = 0; j < neighbors.length; j++) {
- _loop_5(j);
- }
- }
- ListPool.free(colliders);
- this.checkForExitedColliders();
- };
- ColliderTriggerHelper.prototype.checkForExitedColliders = function () {
- var _this = this;
- var _loop_6 = function (i) {
- var index = this_2._previousTriggerIntersections.findIndex(function (value) {
- if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second)
- return true;
- return false;
- });
- if (index != -1)
- this_2._previousTriggerIntersections.removeAt(index);
+ PostProcessor.prototype.onAddedToScene = function (scene) {
+ this.scene = scene;
+ this.shape = new egret.Shape();
+ this.shape.graphics.beginFill(0xFFFFFF, 1);
+ this.shape.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height);
+ this.shape.graphics.endFill();
+ scene.addChild(this.shape);
};
- var this_2 = this;
- for (var i = 0; i < this._activeTriggerIntersections.length; i++) {
- _loop_6(i);
- }
- for (var i = 0; i < this._previousTriggerIntersections.length; i++) {
- this.notifyTriggerListeners(this._previousTriggerIntersections[i], false);
- }
- this._previousTriggerIntersections.length = 0;
- for (var i = 0; i < this._activeTriggerIntersections.length; i++) {
- if (!this._previousTriggerIntersections.contains(this._activeTriggerIntersections[i])) {
- this._previousTriggerIntersections.push(this._activeTriggerIntersections[i]);
+ PostProcessor.prototype.process = function () {
+ this.drawFullscreenQuad();
+ };
+ PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) {
+ };
+ PostProcessor.prototype.unload = function () {
+ if (this.effect) {
+ this.effect = null;
}
+ this.scene.removeChild(this.shape);
+ this.scene = null;
+ };
+ PostProcessor.prototype.drawFullscreenQuad = function () {
+ this.scene.filters = [this.effect];
+ };
+ PostProcessor.default_vert = "attribute vec2 aVertexPosition;\n" +
+ "attribute vec2 aTextureCoord;\n" +
+ "attribute vec2 aColor;\n" +
+ "uniform vec2 projectionVector;\n" +
+ "varying vec2 vTextureCoord;\n" +
+ "varying vec4 vColor;\n" +
+ "const vec2 center = vec2(-1.0, 1.0);\n" +
+ "void main(void) {\n" +
+ "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
+ "vTextureCoord = aTextureCoord;\n" +
+ "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" +
+ "}";
+ return PostProcessor;
+ }());
+ es.PostProcessor = PostProcessor;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var GaussianBlurPostProcessor = (function (_super) {
+ __extends(GaussianBlurPostProcessor, _super);
+ function GaussianBlurPostProcessor() {
+ return _super !== null && _super.apply(this, arguments) || this;
}
- this._activeTriggerIntersections.length = 0;
- };
- ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) {
- collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList);
- for (var i = 0; i < this._tempTriggerList.length; i++) {
- if (isEntering) {
- this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first);
+ GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) {
+ _super.prototype.onAddedToScene.call(this, scene);
+ this.effect = new es.GaussianBlurEffect();
+ };
+ return GaussianBlurPostProcessor;
+ }(es.PostProcessor));
+ es.GaussianBlurPostProcessor = GaussianBlurPostProcessor;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Renderer = (function () {
+ function Renderer(renderOrder, camera) {
+ if (camera === void 0) { camera = null; }
+ this.renderOrder = 0;
+ this.camera = camera;
+ this.renderOrder = renderOrder;
+ }
+ Renderer.prototype.onAddedToScene = function (scene) {
+ };
+ Renderer.prototype.unload = function () {
+ };
+ Renderer.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) {
+ };
+ Renderer.prototype.compareTo = function (other) {
+ return this.renderOrder - other.renderOrder;
+ };
+ Renderer.prototype.beginRender = function (cam) {
+ };
+ Renderer.prototype.renderAfterStateCheck = function (renderable, cam) {
+ renderable.render(cam);
+ };
+ return Renderer;
+ }());
+ es.Renderer = Renderer;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var DefaultRenderer = (function (_super) {
+ __extends(DefaultRenderer, _super);
+ function DefaultRenderer() {
+ return _super.call(this, 0, null) || this;
+ }
+ DefaultRenderer.prototype.render = function (scene) {
+ var cam = this.camera ? this.camera : scene.camera;
+ this.beginRender(cam);
+ for (var i = 0; i < scene.renderableComponents.count; i++) {
+ var renderable = scene.renderableComponents.buffer[i];
+ if (renderable.enabled && renderable.isVisibleFromCamera(cam))
+ this.renderAfterStateCheck(renderable, cam);
+ }
+ };
+ return DefaultRenderer;
+ }(es.Renderer));
+ es.DefaultRenderer = DefaultRenderer;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var ScreenSpaceRenderer = (function (_super) {
+ __extends(ScreenSpaceRenderer, _super);
+ function ScreenSpaceRenderer() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ ScreenSpaceRenderer.prototype.render = function (scene) {
+ };
+ return ScreenSpaceRenderer;
+ }(es.Renderer));
+ es.ScreenSpaceRenderer = ScreenSpaceRenderer;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var PolyLight = (function (_super) {
+ __extends(PolyLight, _super);
+ function PolyLight(radius, color, power) {
+ var _this = _super.call(this) || this;
+ _this._indices = [];
+ _this.radius = radius;
+ _this.power = power;
+ _this.color = color;
+ _this.computeTriangleIndices();
+ return _this;
+ }
+ Object.defineProperty(PolyLight.prototype, "radius", {
+ get: function () {
+ return this._radius;
+ },
+ set: function (value) {
+ this.setRadius(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ PolyLight.prototype.setRadius = function (radius) {
+ if (radius != this._radius) {
+ this._radius = radius;
+ this._areBoundsDirty = true;
+ }
+ };
+ PolyLight.prototype.render = function (camera) {
+ };
+ PolyLight.prototype.reset = function () {
+ };
+ PolyLight.prototype.computeTriangleIndices = function (totalTris) {
+ if (totalTris === void 0) { totalTris = 20; }
+ this._indices.length = 0;
+ for (var i = 0; i < totalTris; i += 2) {
+ this._indices.push(0);
+ this._indices.push(i + 2);
+ this._indices.push(i + 1);
+ }
+ };
+ return PolyLight;
+ }(es.RenderableComponent));
+ es.PolyLight = PolyLight;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var SceneTransition = (function () {
+ function SceneTransition(sceneLoadAction) {
+ this.sceneLoadAction = sceneLoadAction;
+ this.loadsNewScene = sceneLoadAction != null;
+ }
+ Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", {
+ get: function () {
+ if (!this._hasPreviousSceneRender) {
+ this._hasPreviousSceneRender = true;
+ return false;
+ }
+ return true;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ SceneTransition.prototype.preRender = function () {
+ };
+ SceneTransition.prototype.render = function () {
+ };
+ SceneTransition.prototype.onBeginTransition = function () {
+ return __awaiter(this, void 0, void 0, function () {
+ return __generator(this, function (_a) {
+ switch (_a.label) {
+ case 0: return [4, this.loadNextScene()];
+ case 1:
+ _a.sent();
+ this.transitionComplete();
+ return [2];
+ }
+ });
+ });
+ };
+ SceneTransition.prototype.tickEffectProgressProperty = function (filter, duration, easeType, reverseDirection) {
+ if (reverseDirection === void 0) { reverseDirection = false; }
+ return new Promise(function (resolve) {
+ var start = reverseDirection ? 1 : 0;
+ var end = reverseDirection ? 0 : 1;
+ egret.Tween.get(filter.uniforms).set({ _progress: start }).to({ _progress: end }, duration * 1000, easeType).call(function () {
+ resolve();
+ });
+ });
+ };
+ SceneTransition.prototype.transitionComplete = function () {
+ es.Core._instance._sceneTransition = null;
+ if (this.onTransitionCompleted) {
+ this.onTransitionCompleted();
+ }
+ };
+ SceneTransition.prototype.loadNextScene = function () {
+ return __awaiter(this, void 0, void 0, function () {
+ var _a;
+ return __generator(this, function (_b) {
+ switch (_b.label) {
+ case 0:
+ if (this.onScreenObscured)
+ this.onScreenObscured();
+ if (!this.loadsNewScene) {
+ this.isNewSceneLoaded = true;
+ }
+ _a = es.Core;
+ return [4, this.sceneLoadAction()];
+ case 1:
+ _a.scene = _b.sent();
+ this.isNewSceneLoaded = true;
+ return [2];
+ }
+ });
+ });
+ };
+ return SceneTransition;
+ }());
+ es.SceneTransition = SceneTransition;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var FadeTransition = (function (_super) {
+ __extends(FadeTransition, _super);
+ function FadeTransition(sceneLoadAction) {
+ var _this = _super.call(this, sceneLoadAction) || this;
+ _this.fadeToColor = 0x000000;
+ _this.fadeOutDuration = 0.4;
+ _this.fadeEaseType = egret.Ease.quadInOut;
+ _this.delayBeforeFadeInDuration = 0.1;
+ _this._alpha = 0;
+ _this._mask = new egret.Shape();
+ return _this;
+ }
+ FadeTransition.prototype.onBeginTransition = function () {
+ return __awaiter(this, void 0, void 0, function () {
+ var _this = this;
+ return __generator(this, function (_a) {
+ this._mask.graphics.beginFill(this.fadeToColor, 1);
+ this._mask.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height);
+ this._mask.graphics.endFill();
+ egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType)
+ .call(function () { return __awaiter(_this, void 0, void 0, function () {
+ return __generator(this, function (_a) {
+ switch (_a.label) {
+ case 0: return [4, this.loadNextScene()];
+ case 1:
+ _a.sent();
+ return [2];
+ }
+ });
+ }); }).wait(this.delayBeforeFadeInDuration).call(function () {
+ egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () {
+ _this.transitionComplete();
+ });
+ });
+ return [2];
+ });
+ });
+ };
+ FadeTransition.prototype.render = function () {
+ this._mask.graphics.clear();
+ this._mask.graphics.beginFill(this.fadeToColor, this._alpha);
+ this._mask.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height);
+ this._mask.graphics.endFill();
+ };
+ return FadeTransition;
+ }(es.SceneTransition));
+ es.FadeTransition = FadeTransition;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var WindTransition = (function (_super) {
+ __extends(WindTransition, _super);
+ function WindTransition(sceneLoadAction) {
+ var _this = _super.call(this, sceneLoadAction) || this;
+ _this.duration = 1;
+ _this.easeType = egret.Ease.quadOut;
+ var vertexSrc = "attribute vec2 aVertexPosition;\n" +
+ "attribute vec2 aTextureCoord;\n" +
+ "uniform vec2 projectionVector;\n" +
+ "varying vec2 vTextureCoord;\n" +
+ "const vec2 center = vec2(-1.0, 1.0);\n" +
+ "void main(void) {\n" +
+ " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" +
+ " vTextureCoord = aTextureCoord;\n" +
+ "}";
+ var fragmentSrc = "precision lowp float;\n" +
+ "varying vec2 vTextureCoord;\n" +
+ "uniform sampler2D uSampler;\n" +
+ "uniform float _progress;\n" +
+ "uniform float _size;\n" +
+ "uniform float _windSegments;\n" +
+ "void main(void) {\n" +
+ "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" +
+ "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" +
+ "float r = x - floor(x);\n" +
+ "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" +
+ "vec4 fg = texture2D(uSampler, vTextureCoord);\n" +
+ "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" +
+ "}";
+ _this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, {
+ _progress: 0,
+ _size: 0.3,
+ _windSegments: 100
+ });
+ _this._mask = new egret.Shape();
+ _this._mask.graphics.beginFill(0xFFFFFF, 1);
+ _this._mask.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height);
+ _this._mask.graphics.endFill();
+ _this._mask.filters = [_this._windEffect];
+ return _this;
+ }
+ Object.defineProperty(WindTransition.prototype, "windSegments", {
+ set: function (value) {
+ this._windEffect.uniforms._windSegments = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(WindTransition.prototype, "size", {
+ set: function (value) {
+ this._windEffect.uniforms._size = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ WindTransition.prototype.onBeginTransition = function () {
+ return __awaiter(this, void 0, void 0, function () {
+ return __generator(this, function (_a) {
+ switch (_a.label) {
+ case 0:
+ this.loadNextScene();
+ return [4, this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType)];
+ case 1:
+ _a.sent();
+ this.transitionComplete();
+ return [2];
+ }
+ });
+ });
+ };
+ return WindTransition;
+ }(es.SceneTransition));
+ es.WindTransition = WindTransition;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Bezier = (function () {
+ function Bezier() {
+ }
+ Bezier.getPoint = function (p0, p1, p2, t) {
+ t = es.MathHelper.clamp01(t);
+ var oneMinusT = 1 - t;
+ return es.Vector2.add(es.Vector2.add(es.Vector2.multiply(new es.Vector2(oneMinusT * oneMinusT), p0), es.Vector2.multiply(new es.Vector2(2 * oneMinusT * t), p1)), es.Vector2.multiply(new es.Vector2(t * t), p2));
+ };
+ Bezier.getFirstDerivative = function (p0, p1, p2, t) {
+ return es.Vector2.add(es.Vector2.multiply(new es.Vector2(2 * (1 - t)), es.Vector2.subtract(p1, p0)), es.Vector2.multiply(new es.Vector2(2 * t), es.Vector2.subtract(p2, p1)));
+ };
+ Bezier.getFirstDerivativeThree = function (start, firstControlPoint, secondControlPoint, end, t) {
+ t = es.MathHelper.clamp01(t);
+ var oneMunusT = 1 - t;
+ return es.Vector2.add(es.Vector2.add(es.Vector2.multiply(new es.Vector2(3 * oneMunusT * oneMunusT), es.Vector2.subtract(firstControlPoint, start)), es.Vector2.multiply(new es.Vector2(6 * oneMunusT * t), es.Vector2.subtract(secondControlPoint, firstControlPoint))), es.Vector2.multiply(new es.Vector2(3 * t * t), es.Vector2.subtract(end, secondControlPoint)));
+ };
+ Bezier.getPointThree = function (start, firstControlPoint, secondControlPoint, end, t) {
+ t = es.MathHelper.clamp01(t);
+ var oneMunusT = 1 - t;
+ return es.Vector2.add(es.Vector2.add(es.Vector2.add(es.Vector2.multiply(new es.Vector2(oneMunusT * oneMunusT * oneMunusT), start), es.Vector2.multiply(new es.Vector2(3 * oneMunusT * oneMunusT * t), firstControlPoint)), es.Vector2.multiply(new es.Vector2(3 * oneMunusT * t * t), secondControlPoint)), es.Vector2.multiply(new es.Vector2(t * t * t), end));
+ };
+ Bezier.getOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, distanceTolerance) {
+ if (distanceTolerance === void 0) { distanceTolerance = 1; }
+ var points = es.ListPool.obtain();
+ points.push(start);
+ this.recursiveGetOptimizedDrawingPoints(start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance);
+ points.push(end);
+ return points;
+ };
+ Bezier.recursiveGetOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance) {
+ var pt12 = es.Vector2.divide(es.Vector2.add(start, firstCtrlPoint), new es.Vector2(2));
+ var pt23 = es.Vector2.divide(es.Vector2.add(firstCtrlPoint, secondCtrlPoint), new es.Vector2(2));
+ var pt34 = es.Vector2.divide(es.Vector2.add(secondCtrlPoint, end), new es.Vector2(2));
+ var pt123 = es.Vector2.divide(es.Vector2.add(pt12, pt23), new es.Vector2(2));
+ var pt234 = es.Vector2.divide(es.Vector2.add(pt23, pt34), new es.Vector2(2));
+ var pt1234 = es.Vector2.divide(es.Vector2.add(pt123, pt234), new es.Vector2(2));
+ var deltaLine = es.Vector2.subtract(end, start);
+ var d2 = Math.abs(((firstCtrlPoint.x, end.x) * deltaLine.y - (firstCtrlPoint.y - end.y) * deltaLine.x));
+ var d3 = Math.abs(((secondCtrlPoint.x - end.x) * deltaLine.y - (secondCtrlPoint.y - end.y) * deltaLine.x));
+ if ((d2 + d3) * (d2 + d3) < distanceTolerance * (deltaLine.x * deltaLine.x + deltaLine.y * deltaLine.y)) {
+ points.push(pt1234);
+ return;
+ }
+ this.recursiveGetOptimizedDrawingPoints(start, pt12, pt123, pt1234, points, distanceTolerance);
+ this.recursiveGetOptimizedDrawingPoints(pt1234, pt234, pt34, end, points, distanceTolerance);
+ };
+ return Bezier;
+ }());
+ es.Bezier = Bezier;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Flags = (function () {
+ function Flags() {
+ }
+ Flags.isFlagSet = function (self, flag) {
+ return (self & flag) != 0;
+ };
+ Flags.isUnshiftedFlagSet = function (self, flag) {
+ flag = 1 << flag;
+ return (self & flag) != 0;
+ };
+ Flags.setFlagExclusive = function (self, flag) {
+ return 1 << flag;
+ };
+ Flags.setFlag = function (self, flag) {
+ return (self | 1 << flag);
+ };
+ Flags.unsetFlag = function (self, flag) {
+ flag = 1 << flag;
+ return (self & (~flag));
+ };
+ Flags.invertFlags = function (self) {
+ return ~self;
+ };
+ return Flags;
+ }());
+ es.Flags = Flags;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var MathHelper = (function () {
+ function MathHelper() {
+ }
+ MathHelper.toDegrees = function (radians) {
+ return radians * 57.295779513082320876798154814105;
+ };
+ MathHelper.toRadians = function (degrees) {
+ return degrees * 0.017453292519943295769236907684886;
+ };
+ MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) {
+ return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin);
+ };
+ MathHelper.lerp = function (value1, value2, amount) {
+ return value1 + (value2 - value1) * amount;
+ };
+ MathHelper.clamp = function (value, min, max) {
+ if (value < min)
+ return min;
+ if (value > max)
+ return max;
+ return value;
+ };
+ MathHelper.pointOnCirlce = function (circleCenter, radius, angleInDegrees) {
+ var radians = MathHelper.toRadians(angleInDegrees);
+ return new es.Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y);
+ };
+ MathHelper.isEven = function (value) {
+ return value % 2 == 0;
+ };
+ MathHelper.clamp01 = function (value) {
+ if (value < 0)
+ return 0;
+ if (value > 1)
+ return 1;
+ return value;
+ };
+ MathHelper.angleBetweenVectors = function (from, to) {
+ return Math.atan2(to.y - from.y, to.x - from.x);
+ };
+ MathHelper.Epsilon = 0.00001;
+ MathHelper.Rad2Deg = 57.29578;
+ MathHelper.Deg2Rad = 0.0174532924;
+ return MathHelper;
+ }());
+ es.MathHelper = MathHelper;
+})(es || (es = {}));
+var es;
+(function (es) {
+ es.matrixPool = [];
+ var Matrix2D = (function (_super) {
+ __extends(Matrix2D, _super);
+ function Matrix2D() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ Object.defineProperty(Matrix2D.prototype, "m11", {
+ get: function () {
+ return this.a;
+ },
+ set: function (value) {
+ this.a = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Matrix2D.prototype, "m12", {
+ get: function () {
+ return this.b;
+ },
+ set: function (value) {
+ this.b = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Matrix2D.prototype, "m21", {
+ get: function () {
+ return this.c;
+ },
+ set: function (value) {
+ this.c = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Matrix2D.prototype, "m22", {
+ get: function () {
+ return this.d;
+ },
+ set: function (value) {
+ this.d = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Matrix2D.prototype, "m31", {
+ get: function () {
+ return this.tx;
+ },
+ set: function (value) {
+ this.tx = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Matrix2D.prototype, "m32", {
+ get: function () {
+ return this.ty;
+ },
+ set: function (value) {
+ this.ty = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Matrix2D.create = function () {
+ var matrix = es.matrixPool.pop();
+ if (!matrix)
+ matrix = new Matrix2D();
+ return matrix;
+ };
+ Matrix2D.prototype.identity = function () {
+ this.a = this.d = 1;
+ this.b = this.c = this.tx = this.ty = 0;
+ return this;
+ };
+ Matrix2D.prototype.translate = function (dx, dy) {
+ this.tx += dx;
+ this.ty += dy;
+ return this;
+ };
+ Matrix2D.prototype.scale = function (sx, sy) {
+ if (sx !== 1) {
+ this.a *= sx;
+ this.c *= sx;
+ this.tx *= sx;
+ }
+ if (sy !== 1) {
+ this.b *= sy;
+ this.d *= sy;
+ this.ty *= sy;
+ }
+ return this;
+ };
+ Matrix2D.prototype.rotate = function (angle) {
+ angle = +angle;
+ if (angle !== 0) {
+ angle = angle / DEG_TO_RAD;
+ var u = Math.cos(angle);
+ var v = Math.sin(angle);
+ var ta = this.a;
+ var tb = this.b;
+ var tc = this.c;
+ var td = this.d;
+ var ttx = this.tx;
+ var tty = this.ty;
+ this.a = ta * u - tb * v;
+ this.b = ta * v + tb * u;
+ this.c = tc * u - td * v;
+ this.d = tc * v + td * u;
+ this.tx = ttx * u - tty * v;
+ this.ty = ttx * v + tty * u;
+ }
+ return this;
+ };
+ Matrix2D.prototype.invert = function () {
+ this.$invertInto(this);
+ return this;
+ };
+ Matrix2D.prototype.add = function (matrix) {
+ this.m11 += matrix.m11;
+ this.m12 += matrix.m12;
+ this.m21 += matrix.m21;
+ this.m22 += matrix.m22;
+ this.m31 += matrix.m31;
+ this.m32 += matrix.m32;
+ return this;
+ };
+ Matrix2D.prototype.substract = function (matrix) {
+ this.m11 -= matrix.m11;
+ this.m12 -= matrix.m12;
+ this.m21 -= matrix.m21;
+ this.m22 -= matrix.m22;
+ this.m31 -= matrix.m31;
+ this.m32 -= matrix.m32;
+ return this;
+ };
+ Matrix2D.prototype.divide = function (matrix) {
+ this.m11 /= matrix.m11;
+ this.m12 /= matrix.m12;
+ this.m21 /= matrix.m21;
+ this.m22 /= matrix.m22;
+ this.m31 /= matrix.m31;
+ this.m32 /= matrix.m32;
+ return this;
+ };
+ Matrix2D.prototype.multiply = function (matrix) {
+ var m11 = (this.m11 * matrix.m11) + (this.m12 * matrix.m21);
+ var m12 = (this.m11 * matrix.m12) + (this.m12 * matrix.m22);
+ var m21 = (this.m21 * matrix.m11) + (this.m22 * matrix.m21);
+ var m22 = (this.m21 * matrix.m12) + (this.m22 * matrix.m22);
+ var m31 = (this.m31 * matrix.m11) + (this.m32 * matrix.m21) + matrix.m31;
+ var m32 = (this.m31 * matrix.m12) + (this.m32 * matrix.m22) + matrix.m32;
+ this.m11 = m11;
+ this.m12 = m12;
+ this.m21 = m21;
+ this.m22 = m22;
+ this.m31 = m31;
+ this.m32 = m32;
+ return this;
+ };
+ Matrix2D.prototype.determinant = function () {
+ return this.m11 * this.m22 - this.m12 * this.m21;
+ };
+ Matrix2D.prototype.release = function (matrix) {
+ if (!matrix)
+ return;
+ es.matrixPool.push(matrix);
+ };
+ return Matrix2D;
+ }(egret.Matrix));
+ es.Matrix2D = Matrix2D;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Rectangle = (function (_super) {
+ __extends(Rectangle, _super);
+ function Rectangle() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ Object.defineProperty(Rectangle.prototype, "max", {
+ get: function () {
+ return new es.Vector2(this.right, this.bottom);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "center", {
+ get: function () {
+ return new es.Vector2(this.x + (this.width / 2), this.y + (this.height / 2));
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "location", {
+ get: function () {
+ return new es.Vector2(this.x, this.y);
+ },
+ set: function (value) {
+ this.x = value.x;
+ this.y = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "size", {
+ get: function () {
+ return new es.Vector2(this.width, this.height);
+ },
+ set: function (value) {
+ this.width = value.x;
+ this.height = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Rectangle.fromMinMax = function (minX, minY, maxX, maxY) {
+ return new Rectangle(minX, minY, maxX - minX, maxY - minY);
+ };
+ Rectangle.rectEncompassingPoints = function (points) {
+ var minX = Number.POSITIVE_INFINITY;
+ var minY = Number.POSITIVE_INFINITY;
+ var maxX = Number.NEGATIVE_INFINITY;
+ var maxY = Number.NEGATIVE_INFINITY;
+ for (var i = 0; i < points.length; i++) {
+ var pt = points[i];
+ if (pt.x < minX)
+ minX = pt.x;
+ if (pt.x > maxX)
+ maxX = pt.x;
+ if (pt.y < minY)
+ minY = pt.y;
+ if (pt.y > maxY)
+ maxY = pt.y;
+ }
+ return this.fromMinMax(minX, minY, maxX, maxY);
+ };
+ Rectangle.prototype.intersects = function (value) {
+ return value.left < this.right &&
+ this.left < value.right &&
+ value.top < this.bottom &&
+ this.top < value.bottom;
+ };
+ Rectangle.prototype.rayIntersects = function (ray) {
+ var distance = 0;
+ var maxValue = Number.MAX_VALUE;
+ if (Math.abs(ray.direction.x) < 1E-06) {
+ if ((ray.start.x < this.x) || (ray.start.x > this.x + this.width))
+ return distance;
}
else {
- this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first);
+ var num11 = 1 / ray.direction.x;
+ var num8 = (this.x - ray.start.x) * num11;
+ var num7 = (this.x + this.width - ray.start.x) * num11;
+ if (num8 > num7) {
+ var num14 = num8;
+ num8 = num7;
+ num7 = num14;
+ }
+ distance = Math.max(num8, distance);
+ maxValue = Math.min(num7, maxValue);
+ if (distance > maxValue)
+ return distance;
}
- this._tempTriggerList.length = 0;
- if (collisionPair.second.entity) {
- collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList);
- for (var i_2 = 0; i_2 < this._tempTriggerList.length; i_2++) {
- if (isEntering) {
- this._tempTriggerList[i_2].onTriggerEnter(collisionPair.first, collisionPair.second);
- }
- else {
- this._tempTriggerList[i_2].onTriggerExit(collisionPair.first, collisionPair.second);
+ if (Math.abs(ray.direction.y) < 1E-06) {
+ if ((ray.start.y < this.y) || (ray.start.y > this.y + this.height))
+ return distance;
+ }
+ else {
+ var num10 = 1 / ray.direction.y;
+ var num6 = (this.y - ray.start.y) * num10;
+ var num5 = (this.y + this.height - ray.start.y) * num10;
+ if (num6 > num5) {
+ var num13 = num6;
+ num6 = num5;
+ num5 = num13;
+ }
+ distance = Math.max(num6, distance);
+ maxValue = Math.max(num5, maxValue);
+ if (distance > maxValue)
+ return distance;
+ }
+ return distance;
+ };
+ Rectangle.prototype.containsRect = function (value) {
+ return ((((this.x <= value.x) && (value.x < (this.x + this.width))) &&
+ (this.y <= value.y)) &&
+ (value.y < (this.y + this.height)));
+ };
+ Rectangle.prototype.contains = function (x, y) {
+ return ((((this.x <= x) && (x < (this.x + this.width))) && (this.y <= y)) && (y < (this.y + this.height)));
+ };
+ Rectangle.prototype.getHalfSize = function () {
+ return new es.Vector2(this.width * 0.5, this.height * 0.5);
+ };
+ Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point, edgeNormal) {
+ edgeNormal = es.Vector2.zero;
+ var res = new es.Vector2();
+ res.x = es.MathHelper.clamp(point.x, this.left, this.right);
+ res.y = es.MathHelper.clamp(point.y, this.top, this.bottom);
+ if (this.contains(res.x, res.y)) {
+ var dl = res.x - this.left;
+ var dr = this.right - res.x;
+ var dt = res.y - this.top;
+ var db = this.bottom - res.y;
+ var min = Math.min(dl, dr, dt, db);
+ if (min == dt) {
+ res.y = this.top;
+ edgeNormal.y = -1;
+ }
+ else if (min == db) {
+ res.y = this.bottom;
+ edgeNormal.y = 1;
+ }
+ else if (min == dl) {
+ res.x = this.left;
+ edgeNormal.x = -1;
+ }
+ else {
+ res.x = this.right;
+ edgeNormal.x = 1;
+ }
+ }
+ else {
+ if (res.x == this.left)
+ edgeNormal.x = -1;
+ if (res.x == this.right)
+ edgeNormal.x = 1;
+ if (res.y == this.top)
+ edgeNormal.y = -1;
+ if (res.y == this.bottom)
+ edgeNormal.y = 1;
+ }
+ return res;
+ };
+ Rectangle.prototype.getClosestPointOnBoundsToOrigin = function () {
+ var max = this.max;
+ var minDist = Math.abs(this.location.x);
+ var boundsPoint = new es.Vector2(this.location.x, 0);
+ if (Math.abs(max.x) < minDist) {
+ minDist = Math.abs(max.x);
+ boundsPoint.x = max.x;
+ boundsPoint.y = 0;
+ }
+ if (Math.abs(max.y) < minDist) {
+ minDist = Math.abs(max.y);
+ boundsPoint.x = 0;
+ boundsPoint.y = max.y;
+ }
+ if (Math.abs(this.location.y) < minDist) {
+ minDist = Math.abs(this.location.y);
+ boundsPoint.x = 0;
+ boundsPoint.y = this.location.y;
+ }
+ return boundsPoint;
+ };
+ Rectangle.prototype.calculateBounds = function (parentPosition, position, origin, scale, rotation, width, height) {
+ if (rotation == 0) {
+ this.x = parentPosition.x + position.x - origin.x * scale.x;
+ this.y = parentPosition.y + position.y - origin.y * scale.y;
+ this.width = width * scale.x;
+ this.height = height * scale.y;
+ }
+ else {
+ var worldPosX = parentPosition.x + position.x;
+ var worldPosY = parentPosition.y + position.y;
+ this._transformMat = es.Matrix2D.create().translate(-worldPosX - origin.x, -worldPosY - origin.y);
+ this._tempMat = es.Matrix2D.create().scale(scale.x, scale.y);
+ this._transformMat = this._transformMat.multiply(this._tempMat);
+ this._tempMat = es.Matrix2D.create().rotate(rotation);
+ this._transformMat = this._transformMat.multiply(this._tempMat);
+ this._tempMat = es.Matrix2D.create().translate(worldPosX, worldPosY);
+ this._transformMat = this._transformMat.multiply(this._tempMat);
+ var topLeft = new es.Vector2(worldPosX, worldPosY);
+ var topRight = new es.Vector2(worldPosX + width, worldPosY);
+ var bottomLeft = new es.Vector2(worldPosX, worldPosY + height);
+ var bottomRight = new es.Vector2(worldPosX + width, worldPosY + height);
+ topLeft = es.Vector2Ext.transformR(topLeft, this._transformMat);
+ topRight = es.Vector2Ext.transformR(topRight, this._transformMat);
+ bottomLeft = es.Vector2Ext.transformR(bottomLeft, this._transformMat);
+ bottomRight = es.Vector2Ext.transformR(bottomRight, this._transformMat);
+ var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
+ var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
+ var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
+ var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
+ this.location = new es.Vector2(minX, minY);
+ this.width = maxX - minX;
+ this.height = maxY - minY;
+ }
+ };
+ return Rectangle;
+ }(egret.Rectangle));
+ es.Rectangle = Rectangle;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Vector3 = (function () {
+ function Vector3(x, y, z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+ return Vector3;
+ }());
+ es.Vector3 = Vector3;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var ColliderTriggerHelper = (function () {
+ function ColliderTriggerHelper(entity) {
+ this._activeTriggerIntersections = [];
+ this._previousTriggerIntersections = [];
+ this._tempTriggerList = [];
+ this._entity = entity;
+ }
+ ColliderTriggerHelper.prototype.update = function () {
+ var colliders = this._entity.getComponents(es.Collider);
+ for (var i = 0; i < colliders.length; i++) {
+ var collider = colliders[i];
+ var neighbors = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers);
+ var _loop_5 = function (j) {
+ var neighbor = neighbors[j];
+ if (!collider.isTrigger && !neighbor.isTrigger)
+ return "continue";
+ if (collider.overlaps(neighbor)) {
+ var pair_1 = new es.Pair(collider, neighbor);
+ var shouldReportTriggerEvent = this_1._activeTriggerIntersections.findIndex(function (value) {
+ return value.first == pair_1.first && value.second == pair_1.second;
+ }) == -1 && this_1._previousTriggerIntersections.findIndex(function (value) {
+ return value.first == pair_1.first && value.second == pair_1.second;
+ }) == -1;
+ if (shouldReportTriggerEvent)
+ this_1.notifyTriggerListeners(pair_1, true);
+ if (!this_1._activeTriggerIntersections.contains(pair_1))
+ this_1._activeTriggerIntersections.push(pair_1);
}
+ };
+ var this_1 = this;
+ for (var j = 0; j < neighbors.length; j++) {
+ _loop_5(j);
+ }
+ }
+ es.ListPool.free(colliders);
+ this.checkForExitedColliders();
+ };
+ ColliderTriggerHelper.prototype.checkForExitedColliders = function () {
+ var _this = this;
+ var _loop_6 = function (i) {
+ var index = this_2._previousTriggerIntersections.findIndex(function (value) {
+ if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second)
+ return true;
+ return false;
+ });
+ if (index != -1)
+ this_2._previousTriggerIntersections.removeAt(index);
+ };
+ var this_2 = this;
+ for (var i = 0; i < this._activeTriggerIntersections.length; i++) {
+ _loop_6(i);
+ }
+ for (var i = 0; i < this._previousTriggerIntersections.length; i++) {
+ this.notifyTriggerListeners(this._previousTriggerIntersections[i], false);
+ }
+ this._previousTriggerIntersections.length = 0;
+ for (var i = 0; i < this._activeTriggerIntersections.length; i++) {
+ if (!this._previousTriggerIntersections.contains(this._activeTriggerIntersections[i])) {
+ this._previousTriggerIntersections.push(this._activeTriggerIntersections[i]);
+ }
+ }
+ this._activeTriggerIntersections.length = 0;
+ };
+ ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) {
+ collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList);
+ for (var i = 0; i < this._tempTriggerList.length; i++) {
+ if (isEntering) {
+ this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first);
+ }
+ else {
+ this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first);
}
this._tempTriggerList.length = 0;
+ if (collisionPair.second.entity) {
+ collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList);
+ for (var i_2 = 0; i_2 < this._tempTriggerList.length; i_2++) {
+ if (isEntering) {
+ this._tempTriggerList[i_2].onTriggerEnter(collisionPair.first, collisionPair.second);
+ }
+ else {
+ this._tempTriggerList[i_2].onTriggerExit(collisionPair.first, collisionPair.second);
+ }
+ }
+ this._tempTriggerList.length = 0;
+ }
}
+ };
+ return ColliderTriggerHelper;
+ }());
+ es.ColliderTriggerHelper = ColliderTriggerHelper;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var PointSectors;
+ (function (PointSectors) {
+ PointSectors[PointSectors["center"] = 0] = "center";
+ PointSectors[PointSectors["top"] = 1] = "top";
+ PointSectors[PointSectors["bottom"] = 2] = "bottom";
+ PointSectors[PointSectors["topLeft"] = 9] = "topLeft";
+ PointSectors[PointSectors["topRight"] = 5] = "topRight";
+ PointSectors[PointSectors["left"] = 8] = "left";
+ PointSectors[PointSectors["right"] = 4] = "right";
+ PointSectors[PointSectors["bottomLeft"] = 10] = "bottomLeft";
+ PointSectors[PointSectors["bottomRight"] = 6] = "bottomRight";
+ })(PointSectors = es.PointSectors || (es.PointSectors = {}));
+ var Collisions = (function () {
+ function Collisions() {
}
- };
- return ColliderTriggerHelper;
-}());
-var PointSectors;
-(function (PointSectors) {
- PointSectors[PointSectors["center"] = 0] = "center";
- PointSectors[PointSectors["top"] = 1] = "top";
- PointSectors[PointSectors["bottom"] = 2] = "bottom";
- PointSectors[PointSectors["topLeft"] = 9] = "topLeft";
- PointSectors[PointSectors["topRight"] = 5] = "topRight";
- PointSectors[PointSectors["left"] = 8] = "left";
- PointSectors[PointSectors["right"] = 4] = "right";
- PointSectors[PointSectors["bottomLeft"] = 10] = "bottomLeft";
- PointSectors[PointSectors["bottomRight"] = 6] = "bottomRight";
-})(PointSectors || (PointSectors = {}));
-var Collisions = (function () {
- function Collisions() {
- }
- Collisions.isLineToLine = function (a1, a2, b1, b2) {
- var b = Vector2.subtract(a2, a1);
- var d = Vector2.subtract(b2, b1);
- var bDotDPerp = b.x * d.y - b.y * d.x;
- if (bDotDPerp == 0)
- return false;
- var c = Vector2.subtract(b1, a1);
- var t = (c.x * d.y - c.y * d.x) / bDotDPerp;
- if (t < 0 || t > 1)
- return false;
- var u = (c.x * b.y - c.y * b.x) / bDotDPerp;
- if (u < 0 || u > 1)
- return false;
- return true;
- };
- Collisions.lineToLineIntersection = function (a1, a2, b1, b2) {
- var intersection = new Vector2(0, 0);
- var b = Vector2.subtract(a2, a1);
- var d = Vector2.subtract(b2, b1);
- var bDotDPerp = b.x * d.y - b.y * d.x;
- if (bDotDPerp == 0)
- return intersection;
- var c = Vector2.subtract(b1, a1);
- var t = (c.x * d.y - c.y * d.x) / bDotDPerp;
- if (t < 0 || t > 1)
- return intersection;
- var u = (c.x * b.y - c.y * b.x) / bDotDPerp;
- if (u < 0 || u > 1)
- return intersection;
- intersection = Vector2.add(a1, new Vector2(t * b.x, t * b.y));
- return intersection;
- };
- Collisions.closestPointOnLine = function (lineA, lineB, closestTo) {
- var v = Vector2.subtract(lineB, lineA);
- var w = Vector2.subtract(closestTo, lineA);
- var t = Vector2.dot(w, v) / Vector2.dot(v, v);
- t = MathHelper.clamp(t, 0, 1);
- return Vector2.add(lineA, new Vector2(v.x * t, v.y * t));
- };
- Collisions.isCircleToCircle = function (circleCenter1, circleRadius1, circleCenter2, circleRadius2) {
- return Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2);
- };
- Collisions.isCircleToLine = function (circleCenter, radius, lineFrom, lineTo) {
- return Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius;
- };
- Collisions.isCircleToPoint = function (circleCenter, radius, point) {
- return Vector2.distanceSquared(circleCenter, point) < radius * radius;
- };
- Collisions.isRectToCircle = function (rect, cPosition, cRadius) {
- var ew = rect.width * 0.5;
- var eh = rect.height * 0.5;
- var vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew);
- var vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh);
- return vx * vx + vy * vy < cRadius * cRadius;
- };
- Collisions.isRectToLine = function (rect, lineFrom, lineTo) {
- var fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom);
- var toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo);
- if (fromSector == PointSectors.center || toSector == PointSectors.center) {
+ Collisions.isLineToLine = function (a1, a2, b1, b2) {
+ var b = es.Vector2.subtract(a2, a1);
+ var d = es.Vector2.subtract(b2, b1);
+ var bDotDPerp = b.x * d.y - b.y * d.x;
+ if (bDotDPerp == 0)
+ return false;
+ var c = es.Vector2.subtract(b1, a1);
+ var t = (c.x * d.y - c.y * d.x) / bDotDPerp;
+ if (t < 0 || t > 1)
+ return false;
+ var u = (c.x * b.y - c.y * b.x) / bDotDPerp;
+ if (u < 0 || u > 1)
+ return false;
return true;
- }
- else if ((fromSector & toSector) != 0) {
+ };
+ Collisions.lineToLineIntersection = function (a1, a2, b1, b2) {
+ var intersection = new es.Vector2(0, 0);
+ var b = es.Vector2.subtract(a2, a1);
+ var d = es.Vector2.subtract(b2, b1);
+ var bDotDPerp = b.x * d.y - b.y * d.x;
+ if (bDotDPerp == 0)
+ return intersection;
+ var c = es.Vector2.subtract(b1, a1);
+ var t = (c.x * d.y - c.y * d.x) / bDotDPerp;
+ if (t < 0 || t > 1)
+ return intersection;
+ var u = (c.x * b.y - c.y * b.x) / bDotDPerp;
+ if (u < 0 || u > 1)
+ return intersection;
+ intersection = es.Vector2.add(a1, new es.Vector2(t * b.x, t * b.y));
+ return intersection;
+ };
+ Collisions.closestPointOnLine = function (lineA, lineB, closestTo) {
+ var v = es.Vector2.subtract(lineB, lineA);
+ var w = es.Vector2.subtract(closestTo, lineA);
+ var t = es.Vector2.dot(w, v) / es.Vector2.dot(v, v);
+ t = es.MathHelper.clamp(t, 0, 1);
+ return es.Vector2.add(lineA, new es.Vector2(v.x * t, v.y * t));
+ };
+ Collisions.isCircleToCircle = function (circleCenter1, circleRadius1, circleCenter2, circleRadius2) {
+ return es.Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2);
+ };
+ Collisions.isCircleToLine = function (circleCenter, radius, lineFrom, lineTo) {
+ return es.Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius;
+ };
+ Collisions.isCircleToPoint = function (circleCenter, radius, point) {
+ return es.Vector2.distanceSquared(circleCenter, point) < radius * radius;
+ };
+ Collisions.isRectToCircle = function (rect, cPosition, cRadius) {
+ var ew = rect.width * 0.5;
+ var eh = rect.height * 0.5;
+ var vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew);
+ var vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh);
+ return vx * vx + vy * vy < cRadius * cRadius;
+ };
+ Collisions.isRectToLine = function (rect, lineFrom, lineTo) {
+ var fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom);
+ var toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo);
+ if (fromSector == PointSectors.center || toSector == PointSectors.center) {
+ return true;
+ }
+ else if ((fromSector & toSector) != 0) {
+ return false;
+ }
+ else {
+ var both = fromSector | toSector;
+ var edgeFrom = void 0;
+ var edgeTo = void 0;
+ if ((both & PointSectors.top) != 0) {
+ edgeFrom = new es.Vector2(rect.x, rect.y);
+ edgeTo = new es.Vector2(rect.x + rect.width, rect.y);
+ if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo))
+ return true;
+ }
+ if ((both & PointSectors.bottom) != 0) {
+ edgeFrom = new es.Vector2(rect.x, rect.y + rect.height);
+ edgeTo = new es.Vector2(rect.x + rect.width, rect.y + rect.height);
+ if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo))
+ return true;
+ }
+ if ((both & PointSectors.left) != 0) {
+ edgeFrom = new es.Vector2(rect.x, rect.y);
+ edgeTo = new es.Vector2(rect.x, rect.y + rect.height);
+ if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo))
+ return true;
+ }
+ if ((both & PointSectors.right) != 0) {
+ edgeFrom = new es.Vector2(rect.x + rect.width, rect.y);
+ edgeTo = new es.Vector2(rect.x + rect.width, rect.y + rect.height);
+ if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo))
+ return true;
+ }
+ }
return false;
+ };
+ Collisions.isRectToPoint = function (rX, rY, rW, rH, point) {
+ return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH;
+ };
+ Collisions.getSector = function (rX, rY, rW, rH, point) {
+ var sector = PointSectors.center;
+ if (point.x < rX)
+ sector |= PointSectors.left;
+ else if (point.x >= rX + rW)
+ sector |= PointSectors.right;
+ if (point.y < rY)
+ sector |= PointSectors.top;
+ else if (point.y >= rY + rH)
+ sector |= PointSectors.bottom;
+ return sector;
+ };
+ return Collisions;
+ }());
+ es.Collisions = Collisions;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Physics = (function () {
+ function Physics() {
}
- else {
- var both = fromSector | toSector;
- var edgeFrom = void 0;
- var edgeTo = void 0;
- if ((both & PointSectors.top) != 0) {
- edgeFrom = new Vector2(rect.x, rect.y);
- edgeTo = new Vector2(rect.x + rect.width, rect.y);
- if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo))
+ Physics.reset = function () {
+ this._spatialHash = new es.SpatialHash(this.spatialHashCellSize);
+ };
+ Physics.clear = function () {
+ this._spatialHash.clear();
+ };
+ Physics.overlapCircleAll = function (center, randius, results, layerMask) {
+ if (layerMask === void 0) { layerMask = -1; }
+ if (results.length == 0) {
+ console.error("An empty results array was passed in. No results will ever be returned.");
+ return;
+ }
+ return this._spatialHash.overlapCircle(center, randius, results, layerMask);
+ };
+ Physics.boxcastBroadphase = function (rect, layerMask) {
+ if (layerMask === void 0) { layerMask = this.allLayers; }
+ return this._spatialHash.aabbBroadphase(rect, null, layerMask);
+ };
+ Physics.boxcastBroadphaseExcludingSelf = function (collider, rect, layerMask) {
+ if (layerMask === void 0) { layerMask = this.allLayers; }
+ return this._spatialHash.aabbBroadphase(rect, collider, layerMask);
+ };
+ Physics.addCollider = function (collider) {
+ Physics._spatialHash.register(collider);
+ };
+ Physics.removeCollider = function (collider) {
+ Physics._spatialHash.remove(collider);
+ };
+ Physics.updateCollider = function (collider) {
+ this._spatialHash.remove(collider);
+ this._spatialHash.register(collider);
+ };
+ Physics.debugDraw = function (secondsToDisplay) {
+ this._spatialHash.debugDraw(secondsToDisplay, 2);
+ };
+ Physics.spatialHashCellSize = 100;
+ Physics.allLayers = -1;
+ Physics.raycastsHitTriggers = false;
+ Physics.raycastsStartInColliders = false;
+ return Physics;
+ }());
+ es.Physics = Physics;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Ray2D = (function () {
+ function Ray2D(position, end) {
+ this.start = position;
+ this.end = end;
+ this.direction = es.Vector2.subtract(this.end, this.start);
+ }
+ return Ray2D;
+ }());
+ es.Ray2D = Ray2D;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var RaycastHit = (function () {
+ function RaycastHit(collider, fraction, distance, point, normal) {
+ this.fraction = 0;
+ this.distance = 0;
+ this.point = es.Vector2.zero;
+ this.normal = es.Vector2.zero;
+ this.collider = collider;
+ this.fraction = fraction;
+ this.distance = distance;
+ this.point = point;
+ this.centroid = es.Vector2.zero;
+ }
+ RaycastHit.prototype.setValues = function (collider, fraction, distance, point) {
+ this.collider = collider;
+ this.fraction = fraction;
+ this.distance = distance;
+ this.point = point;
+ };
+ RaycastHit.prototype.setValuesNonCollider = function (fraction, distance, point, normal) {
+ this.fraction = fraction;
+ this.distance = distance;
+ this.point = point;
+ this.normal = normal;
+ };
+ RaycastHit.prototype.reset = function () {
+ this.collider = null;
+ this.fraction = this.distance = 0;
+ };
+ RaycastHit.prototype.toString = function () {
+ return "[RaycastHit] fraction: " + this.fraction + ", distance: " + this.distance + ", normal: " + this.normal + ", centroid: " + this.centroid + ", point: " + this.point;
+ };
+ return RaycastHit;
+ }());
+ es.RaycastHit = RaycastHit;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Shape = (function () {
+ function Shape() {
+ }
+ Shape.prototype.clone = function () {
+ return ObjectUtils.clone(this);
+ };
+ return Shape;
+ }());
+ es.Shape = Shape;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Polygon = (function (_super) {
+ __extends(Polygon, _super);
+ function Polygon(points, isBox) {
+ var _this = _super.call(this) || this;
+ _this._areEdgeNormalsDirty = true;
+ _this.isUnrotated = true;
+ _this.setPoints(points);
+ _this.isBox = isBox;
+ return _this;
+ }
+ Object.defineProperty(Polygon.prototype, "edgeNormals", {
+ get: function () {
+ if (this._areEdgeNormalsDirty)
+ this.buildEdgeNormals();
+ return this._edgeNormals;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Polygon.prototype.setPoints = function (points) {
+ this.points = points;
+ this.recalculateCenterAndEdgeNormals();
+ this._originalPoints = [];
+ for (var i = 0; i < this.points.length; i++) {
+ this._originalPoints.push(this.points[i]);
+ }
+ };
+ Polygon.prototype.recalculateCenterAndEdgeNormals = function () {
+ this._polygonCenter = Polygon.findPolygonCenter(this.points);
+ this._areEdgeNormalsDirty = true;
+ };
+ Polygon.prototype.buildEdgeNormals = function () {
+ var totalEdges = this.isBox ? 2 : this.points.length;
+ if (this._edgeNormals == null || this._edgeNormals.length != totalEdges)
+ this._edgeNormals = new Array(totalEdges);
+ var p2;
+ for (var i = 0; i < totalEdges; i++) {
+ var p1 = this.points[i];
+ if (i + 1 >= this.points.length)
+ p2 = this.points[0];
+ else
+ p2 = this.points[i + 1];
+ var perp = es.Vector2Ext.perpendicular(p1, p2);
+ perp = es.Vector2.normalize(perp);
+ this._edgeNormals[i] = perp;
+ }
+ };
+ Polygon.buildSymmetricalPolygon = function (vertCount, radius) {
+ var verts = new Array(vertCount);
+ for (var i = 0; i < vertCount; i++) {
+ var a = 2 * Math.PI * (i / vertCount);
+ verts[i] = es.Vector2.multiply(new es.Vector2(Math.cos(a), Math.sin(a)), new es.Vector2(radius));
+ }
+ return verts;
+ };
+ Polygon.recenterPolygonVerts = function (points) {
+ var center = this.findPolygonCenter(points);
+ for (var i = 0; i < points.length; i++)
+ points[i] = es.Vector2.subtract(points[i], center);
+ };
+ Polygon.findPolygonCenter = function (points) {
+ var x = 0, y = 0;
+ for (var i = 0; i < points.length; i++) {
+ x += points[i].x;
+ y += points[i].y;
+ }
+ return new es.Vector2(x / points.length, y / points.length);
+ };
+ Polygon.getFarthestPointInDirection = function (points, direction) {
+ var index = 0;
+ var maxDot = es.Vector2.dot(points[index], direction);
+ for (var i = 1; i < points.length; i++) {
+ var dot = es.Vector2.dot(points[i], direction);
+ if (dot > maxDot) {
+ maxDot = dot;
+ index = i;
+ }
+ }
+ return points[index];
+ };
+ Polygon.getClosestPointOnPolygonToPoint = function (points, point, distanceSquared, edgeNormal) {
+ distanceSquared = Number.MAX_VALUE;
+ edgeNormal = new es.Vector2(0, 0);
+ var closestPoint = new es.Vector2(0, 0);
+ var tempDistanceSquared;
+ for (var i = 0; i < points.length; i++) {
+ var j = i + 1;
+ if (j == points.length)
+ j = 0;
+ var closest = es.ShapeCollisions.closestPointOnLine(points[i], points[j], point);
+ tempDistanceSquared = es.Vector2.distanceSquared(point, closest);
+ if (tempDistanceSquared < distanceSquared) {
+ distanceSquared = tempDistanceSquared;
+ closestPoint = closest;
+ var line = es.Vector2.subtract(points[j], points[i]);
+ edgeNormal = new es.Vector2(-line.y, line.x);
+ }
+ }
+ es.Vector2Ext.normalize(edgeNormal);
+ return closestPoint;
+ };
+ Polygon.rotatePolygonVerts = function (radians, originalPoints, rotatedPoints) {
+ var cos = Math.cos(radians);
+ var sin = Math.sign(radians);
+ for (var i = 0; i < originalPoints.length; i++) {
+ var position = originalPoints[i];
+ rotatedPoints[i] = new es.Vector2(position.x * cos + position.y * -sin, position.x * sin + position.y * cos);
+ }
+ };
+ Polygon.prototype.recalculateBounds = function (collider) {
+ this.center = collider.localOffset;
+ if (collider.shouldColliderScaleAndRotateWithTransform) {
+ var hasUnitScale = true;
+ var tempMat = void 0;
+ var combinedMatrix = es.Matrix2D.create().translate(-this._polygonCenter.x, -this._polygonCenter.y);
+ if (collider.entity.transform.scale != es.Vector2.zero) {
+ tempMat = es.Matrix2D.create().scale(collider.entity.transform.scale.x, collider.entity.transform.scale.y);
+ combinedMatrix = combinedMatrix.multiply(tempMat);
+ hasUnitScale = false;
+ this.center = es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale);
+ }
+ if (collider.entity.transform.rotation != 0) {
+ tempMat = es.Matrix2D.create().rotate(collider.entity.transform.rotation);
+ combinedMatrix = combinedMatrix.multiply(tempMat);
+ var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg;
+ var offsetLength = hasUnitScale ? collider._localOffsetLength :
+ es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
+ this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle);
+ }
+ tempMat = es.Matrix2D.create().translate(this._polygonCenter.x, this._polygonCenter.y);
+ combinedMatrix = combinedMatrix.multiply(tempMat);
+ es.Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points);
+ this.isUnrotated = collider.entity.transform.rotation == 0;
+ if (collider._isRotationDirty)
+ this._areEdgeNormalsDirty = true;
+ }
+ this.position = es.Vector2.add(collider.entity.transform.position, this.center);
+ this.bounds = es.Rectangle.rectEncompassingPoints(this.points);
+ this.bounds.location = this.bounds.location.add(this.position);
+ };
+ Polygon.prototype.overlaps = function (other) {
+ var result = new es.CollisionResult();
+ if (other instanceof Polygon)
+ return es.ShapeCollisions.polygonToPolygon(this, other, result);
+ if (other instanceof es.Circle) {
+ if (es.ShapeCollisions.circleToPolygon(other, this, result)) {
+ result.invertResult();
return true;
+ }
+ return false;
}
- if ((both & PointSectors.bottom) != 0) {
- edgeFrom = new Vector2(rect.x, rect.y + rect.height);
- edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height);
- if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo))
+ throw new Error("overlaps of Pologon to " + other + " are not supported");
+ };
+ Polygon.prototype.collidesWithShape = function (other, result) {
+ if (other instanceof Polygon) {
+ return es.ShapeCollisions.polygonToPolygon(this, other, result);
+ }
+ if (other instanceof es.Circle) {
+ if (es.ShapeCollisions.circleToPolygon(other, this, result)) {
+ result.invertResult();
return true;
+ }
+ return false;
}
- if ((both & PointSectors.left) != 0) {
- edgeFrom = new Vector2(rect.x, rect.y);
- edgeTo = new Vector2(rect.x, rect.y + rect.height);
- if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo))
- return true;
+ throw new Error("overlaps of Polygon to " + other + " are not supported");
+ };
+ Polygon.prototype.collidesWithLine = function (start, end, hit) {
+ return es.ShapeCollisions.lineToPoly(start, end, this, hit);
+ };
+ Polygon.prototype.containsPoint = function (point) {
+ point = es.Vector2.subtract(point, this.position);
+ var isInside = false;
+ for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) {
+ if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) &&
+ (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) +
+ this.points[i].x)) {
+ isInside = !isInside;
+ }
}
- if ((both & PointSectors.right) != 0) {
- edgeFrom = new Vector2(rect.x + rect.width, rect.y);
- edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height);
- if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo))
- return true;
+ return isInside;
+ };
+ Polygon.prototype.pointCollidesWithShape = function (point, result) {
+ return es.ShapeCollisions.pointToPoly(point, this, result);
+ };
+ return Polygon;
+ }(es.Shape));
+ es.Polygon = Polygon;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Box = (function (_super) {
+ __extends(Box, _super);
+ function Box(width, height) {
+ var _this = _super.call(this, Box.buildBox(width, height), true) || this;
+ _this.width = width;
+ _this.height = height;
+ return _this;
+ }
+ Box.buildBox = function (width, height) {
+ var halfWidth = width / 2;
+ var halfHeight = height / 2;
+ var verts = new Array(4);
+ verts[0] = new es.Vector2(-halfWidth, -halfHeight);
+ verts[1] = new es.Vector2(halfWidth, -halfHeight);
+ verts[2] = new es.Vector2(halfWidth, halfHeight);
+ verts[3] = new es.Vector2(-halfWidth, halfHeight);
+ return verts;
+ };
+ Box.prototype.updateBox = function (width, height) {
+ this.width = width;
+ this.height = height;
+ var halfWidth = width / 2;
+ var halfHeight = height / 2;
+ this.points[0] = new es.Vector2(-halfWidth, -halfHeight);
+ this.points[1] = new es.Vector2(halfWidth, -halfHeight);
+ this.points[2] = new es.Vector2(halfWidth, halfHeight);
+ this.points[3] = new es.Vector2(-halfWidth, halfHeight);
+ for (var i = 0; i < this.points.length; i++)
+ this._originalPoints[i] = this.points[i];
+ };
+ Box.prototype.overlaps = function (other) {
+ if (this.isUnrotated) {
+ if (other instanceof Box && other.isUnrotated)
+ return this.bounds.intersects(other.bounds);
+ if (other instanceof es.Circle)
+ return es.Collisions.isRectToCircle(this.bounds, other.position, other.radius);
}
- }
- return false;
- };
- Collisions.isRectToPoint = function (rX, rY, rW, rH, point) {
- return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH;
- };
- Collisions.getSector = function (rX, rY, rW, rH, point) {
- var sector = PointSectors.center;
- if (point.x < rX)
- sector |= PointSectors.left;
- else if (point.x >= rX + rW)
- sector |= PointSectors.right;
- if (point.y < rY)
- sector |= PointSectors.top;
- else if (point.y >= rY + rH)
- sector |= PointSectors.bottom;
- return sector;
- };
- return Collisions;
-}());
-var Physics = (function () {
- function Physics() {
- }
- Physics.reset = function () {
- this._spatialHash = new SpatialHash(this.spatialHashCellSize);
- };
- Physics.clear = function () {
- this._spatialHash.clear();
- };
- Physics.overlapCircleAll = function (center, randius, results, layerMask) {
- if (layerMask === void 0) { layerMask = -1; }
- return this._spatialHash.overlapCircle(center, randius, results, layerMask);
- };
- Physics.boxcastBroadphase = function (rect, layerMask) {
- if (layerMask === void 0) { layerMask = this.allLayers; }
- var boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask);
- return { colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds };
- };
- Physics.boxcastBroadphaseExcludingSelf = function (collider, rect, layerMask) {
- if (layerMask === void 0) { layerMask = this.allLayers; }
- return this._spatialHash.aabbBroadphase(rect, collider, layerMask);
- };
- Physics.addCollider = function (collider) {
- Physics._spatialHash.register(collider);
- };
- Physics.removeCollider = function (collider) {
- Physics._spatialHash.remove(collider);
- };
- Physics.updateCollider = function (collider) {
- this._spatialHash.remove(collider);
- this._spatialHash.register(collider);
- };
- Physics.spatialHashCellSize = 100;
- Physics.allLayers = -1;
- return Physics;
-}());
-var Shape = (function () {
- function Shape() {
- }
- return Shape;
-}());
-var Polygon = (function (_super) {
- __extends(Polygon, _super);
- function Polygon(points, isBox) {
- var _this = _super.call(this) || this;
- _this.isUnrotated = true;
- _this._areEdgeNormalsDirty = true;
- _this.setPoints(points);
- _this.isBox = isBox;
- return _this;
- }
- Object.defineProperty(Polygon.prototype, "edgeNormals", {
- get: function () {
- if (this._areEdgeNormalsDirty)
- this.buildEdgeNormals();
- return this._edgeNormals;
- },
- enumerable: true,
- configurable: true
- });
- Polygon.prototype.buildEdgeNormals = function () {
- var totalEdges = this.isBox ? 2 : this.points.length;
- if (this._edgeNormals == null || this._edgeNormals.length != totalEdges)
- this._edgeNormals = new Array(totalEdges);
- var p2;
- for (var i = 0; i < totalEdges; i++) {
- var p1 = this.points[i];
- if (i + 1 >= this.points.length)
- p2 = this.points[0];
- else
- p2 = this.points[i + 1];
- var perp = Vector2Ext.perpendicular(p1, p2);
- perp = Vector2.normalize(perp);
- this._edgeNormals[i] = perp;
- }
- };
- Polygon.prototype.setPoints = function (points) {
- this.points = points;
- this.recalculateCenterAndEdgeNormals();
- this._originalPoints = [];
- for (var i = 0; i < this.points.length; i++) {
- this._originalPoints.push(this.points[i]);
- }
- };
- Polygon.prototype.collidesWithShape = function (other) {
- var result = new CollisionResult();
- if (other instanceof Polygon) {
- return ShapeCollisions.polygonToPolygon(this, other);
- }
- if (other instanceof Circle) {
- result = ShapeCollisions.circleToPolygon(other, this);
- if (result) {
- result.invertResult();
- return result;
+ return _super.prototype.overlaps.call(this, other);
+ };
+ Box.prototype.collidesWithShape = function (other, result) {
+ if (other instanceof Box && other.isUnrotated) {
+ return es.ShapeCollisions.boxToBox(this, other, result);
}
- return null;
+ return _super.prototype.collidesWithShape.call(this, other, result);
+ };
+ Box.prototype.containsPoint = function (point) {
+ if (this.isUnrotated)
+ return this.bounds.contains(point.x, point.y);
+ return _super.prototype.containsPoint.call(this, point);
+ };
+ Box.prototype.pointCollidesWithShape = function (point, result) {
+ if (this.isUnrotated)
+ return es.ShapeCollisions.pointToBox(point, this, result);
+ return _super.prototype.pointCollidesWithShape.call(this, point, result);
+ };
+ return Box;
+ }(es.Polygon));
+ es.Box = Box;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Circle = (function (_super) {
+ __extends(Circle, _super);
+ function Circle(radius) {
+ var _this = _super.call(this) || this;
+ _this.radius = radius;
+ _this._originalRadius = radius;
+ return _this;
}
- throw new Error("overlaps of Polygon to " + other + " are not supported");
- };
- Polygon.prototype.recalculateCenterAndEdgeNormals = function () {
- this._polygonCenter = Polygon.findPolygonCenter(this.points);
- this._areEdgeNormalsDirty = true;
- };
- Polygon.prototype.overlaps = function (other) {
- var result;
- if (other instanceof Polygon)
- return ShapeCollisions.polygonToPolygon(this, other);
- if (other instanceof Circle) {
- result = ShapeCollisions.circleToPolygon(other, this);
- if (result) {
- result.invertResult();
+ Circle.prototype.recalculateBounds = function (collider) {
+ this.center = collider.localOffset;
+ if (collider.shouldColliderScaleAndRotateWithTransform) {
+ var scale = collider.entity.transform.scale;
+ var hasUnitScale = scale.x == 1 && scale.y == 1;
+ var maxScale = Math.max(scale.x, scale.y);
+ this.radius = this._originalRadius * maxScale;
+ if (collider.entity.transform.rotation != 0) {
+ var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg;
+ var offsetLength = hasUnitScale ? collider._localOffsetLength : es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
+ this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle);
+ }
+ }
+ this.position = es.Vector2.add(collider.transform.position, this.center);
+ this.bounds = new es.Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2);
+ };
+ Circle.prototype.overlaps = function (other) {
+ var result = new es.CollisionResult();
+ if (other instanceof es.Box && other.isUnrotated)
+ return es.Collisions.isRectToCircle(other.bounds, this.position, this.radius);
+ if (other instanceof Circle)
+ return es.Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius);
+ if (other instanceof es.Polygon)
+ return es.ShapeCollisions.circleToPolygon(this, other, result);
+ throw new Error("overlaps of circle to " + other + " are not supported");
+ };
+ Circle.prototype.collidesWithShape = function (other, result) {
+ if (other instanceof es.Box && other.isUnrotated) {
+ return es.ShapeCollisions.circleToBox(this, other, result);
+ }
+ if (other instanceof Circle) {
+ return es.ShapeCollisions.circleToCircle(this, other, result);
+ }
+ if (other instanceof es.Polygon) {
+ return es.ShapeCollisions.circleToPolygon(this, other, result);
+ }
+ throw new Error("Collisions of Circle to " + other + " are not supported");
+ };
+ Circle.prototype.collidesWithLine = function (start, end, hit) {
+ return es.ShapeCollisions.lineToCircle(start, end, this, hit);
+ };
+ Circle.prototype.containsPoint = function (point) {
+ return (es.Vector2.subtract(point, this.position)).lengthSquared() <= this.radius * this.radius;
+ };
+ Circle.prototype.pointCollidesWithShape = function (point, result) {
+ return es.ShapeCollisions.pointToCircle(point, this, result);
+ };
+ return Circle;
+ }(es.Shape));
+ es.Circle = Circle;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var CollisionResult = (function () {
+ function CollisionResult() {
+ this.normal = es.Vector2.zero;
+ this.minimumTranslationVector = es.Vector2.zero;
+ this.point = es.Vector2.zero;
+ }
+ CollisionResult.prototype.removeHorizontal = function (deltaMovement) {
+ if (Math.sign(this.normal.x) != Math.sign(deltaMovement.x) || (deltaMovement.x == 0 && this.normal.x != 0)) {
+ var responseDistance = this.minimumTranslationVector.length();
+ var fix = responseDistance / this.normal.y;
+ if (Math.abs(this.normal.x) != 1 && Math.abs(fix) < Math.abs(deltaMovement.y * 3)) {
+ this.minimumTranslationVector = new es.Vector2(0, -fix);
+ }
+ }
+ };
+ CollisionResult.prototype.invertResult = function () {
+ this.minimumTranslationVector = es.Vector2.negate(this.minimumTranslationVector);
+ this.normal = es.Vector2.negate(this.normal);
+ return this;
+ };
+ CollisionResult.prototype.toString = function () {
+ return "[CollisionResult] normal: " + this.normal + ", minimumTranslationVector: " + this.minimumTranslationVector;
+ };
+ return CollisionResult;
+ }());
+ es.CollisionResult = CollisionResult;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var RealtimeCollisions = (function () {
+ function RealtimeCollisions() {
+ }
+ RealtimeCollisions.intersectMovingCircleToBox = function (s, b, movement) {
+ var e = b.bounds;
+ e.inflate(s.radius, s.radius);
+ var ray = new es.Ray2D(es.Vector2.subtract(s.position, movement), s.position);
+ var time = e.rayIntersects(ray);
+ if (time > 1)
+ return time;
+ var point = es.Vector2.add(ray.start, es.Vector2.add(ray.direction, new es.Vector2(time)));
+ var u, v = 0;
+ if (point.x < b.bounds.left)
+ u |= 1;
+ if (point.x > b.bounds.right)
+ v |= 1;
+ if (point.y < b.bounds.top)
+ u |= 2;
+ if (point.y > b.bounds.bottom)
+ v |= 2;
+ var m = u + v;
+ if (m == 3) {
+ console.log("m == 3. corner " + es.Time.frameCount);
+ }
+ if ((m & (m - 1)) == 0) {
+ return time;
+ }
+ return time;
+ };
+ return RealtimeCollisions;
+ }());
+ es.RealtimeCollisions = RealtimeCollisions;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var ShapeCollisions = (function () {
+ function ShapeCollisions() {
+ }
+ ShapeCollisions.polygonToPolygon = function (first, second, result) {
+ var isIntersecting = true;
+ var firstEdges = first.edgeNormals;
+ var secondEdges = second.edgeNormals;
+ var minIntervalDistance = Number.POSITIVE_INFINITY;
+ var translationAxis = new es.Vector2();
+ var polygonOffset = es.Vector2.subtract(first.position, second.position);
+ var axis;
+ for (var edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) {
+ if (edgeIndex < firstEdges.length) {
+ axis = firstEdges[edgeIndex];
+ }
+ else {
+ axis = secondEdges[edgeIndex - firstEdges.length];
+ }
+ var minA = 0;
+ var minB = 0;
+ var maxA = 0;
+ var maxB = 0;
+ var intervalDist = 0;
+ var ta = this.getInterval(axis, first, minA, maxA);
+ minA = ta.min;
+ minB = ta.max;
+ var tb = this.getInterval(axis, second, minB, maxB);
+ minB = tb.min;
+ maxB = tb.max;
+ var relativeIntervalOffset = es.Vector2.dot(polygonOffset, axis);
+ minA += relativeIntervalOffset;
+ maxA += relativeIntervalOffset;
+ intervalDist = this.intervalDistance(minA, maxA, minB, maxB);
+ if (intervalDist > 0)
+ isIntersecting = false;
+ if (!isIntersecting)
+ return false;
+ intervalDist = Math.abs(intervalDist);
+ if (intervalDist < minIntervalDistance) {
+ minIntervalDistance = intervalDist;
+ translationAxis = axis;
+ if (es.Vector2.dot(translationAxis, polygonOffset) < 0)
+ translationAxis = new es.Vector2(-translationAxis);
+ }
+ }
+ result.normal = translationAxis;
+ result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-translationAxis.x, -translationAxis.y), new es.Vector2(minIntervalDistance));
+ return true;
+ };
+ ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) {
+ if (minA < minB)
+ return minB - maxA;
+ return minA - minB;
+ };
+ ShapeCollisions.getInterval = function (axis, polygon, min, max) {
+ var dot = es.Vector2.dot(polygon.points[0], axis);
+ min = max = dot;
+ for (var i = 1; i < polygon.points.length; i++) {
+ dot = es.Vector2.dot(polygon.points[i], axis);
+ if (dot < min) {
+ min = dot;
+ }
+ else if (dot > max) {
+ max = dot;
+ }
+ }
+ return { min: min, max: max };
+ };
+ ShapeCollisions.circleToPolygon = function (circle, polygon, result) {
+ var poly2Circle = es.Vector2.subtract(circle.position, polygon.position);
+ var distanceSquared = 0;
+ var closestPoint = es.Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle, distanceSquared, result.normal);
+ var circleCenterInsidePoly = polygon.containsPoint(circle.position);
+ if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly)
+ return false;
+ var mtv;
+ if (circleCenterInsidePoly) {
+ mtv = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared) - circle.radius));
+ }
+ else {
+ if (distanceSquared == 0) {
+ mtv = es.Vector2.multiply(result.normal, new es.Vector2(circle.radius));
+ }
+ else {
+ var distance = Math.sqrt(distanceSquared);
+ mtv = es.Vector2.multiply(new es.Vector2(-es.Vector2.subtract(poly2Circle, closestPoint)), new es.Vector2((circle.radius - distanceSquared) / distance));
+ }
+ }
+ result.minimumTranslationVector = mtv;
+ result.point = es.Vector2.add(closestPoint, polygon.position);
+ return true;
+ };
+ ShapeCollisions.circleToBox = function (circle, box, result) {
+ var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal);
+ if (box.containsPoint(circle.position)) {
+ result.point = closestPointOnBounds;
+ var safePlace = es.Vector2.add(closestPointOnBounds, es.Vector2.multiply(result.normal, new es.Vector2(circle.radius)));
+ result.minimumTranslationVector = es.Vector2.subtract(circle.position, safePlace);
+ return true;
+ }
+ var sqrDistance = es.Vector2.distanceSquared(closestPointOnBounds, circle.position);
+ if (sqrDistance == 0) {
+ result.minimumTranslationVector = es.Vector2.multiply(result.normal, new es.Vector2(circle.radius));
+ }
+ else if (sqrDistance <= circle.radius * circle.radius) {
+ result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds);
+ var depth = result.normal.length() - circle.radius;
+ result.point = closestPointOnBounds;
+ result.normal = es.Vector2Ext.normalize(result.normal);
+ result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal);
return true;
}
return false;
- }
- throw new Error("overlaps of Pologon to " + other + " are not supported");
- };
- Polygon.findPolygonCenter = function (points) {
- var x = 0, y = 0;
- for (var i = 0; i < points.length; i++) {
- x += points[i].x;
- y += points[i].y;
- }
- return new Vector2(x / points.length, y / points.length);
- };
- Polygon.getClosestPointOnPolygonToPoint = function (points, point) {
- var distanceSquared = Number.MAX_VALUE;
- var edgeNormal = new Vector2(0, 0);
- var closestPoint = new Vector2(0, 0);
- var tempDistanceSquared;
- for (var i = 0; i < points.length; i++) {
- var j = i + 1;
- if (j == points.length)
- j = 0;
- var closest = ShapeCollisions.closestPointOnLine(points[i], points[j], point);
- tempDistanceSquared = Vector2.distanceSquared(point, closest);
- if (tempDistanceSquared < distanceSquared) {
- distanceSquared = tempDistanceSquared;
- closestPoint = closest;
- var line = Vector2.subtract(points[j], points[i]);
- edgeNormal.x = -line.y;
- edgeNormal.y = line.x;
+ };
+ ShapeCollisions.pointToCircle = function (point, circle, result) {
+ var distanceSquared = es.Vector2.distanceSquared(point, circle.position);
+ var sumOfRadii = 1 + circle.radius;
+ var collided = distanceSquared < sumOfRadii * sumOfRadii;
+ if (collided) {
+ result.normal = es.Vector2.normalize(es.Vector2.subtract(point, circle.position));
+ var depth = sumOfRadii - Math.sqrt(distanceSquared);
+ result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-depth, -depth), result.normal);
+ result.point = es.Vector2.add(circle.position, es.Vector2.multiply(result.normal, new es.Vector2(circle.radius, circle.radius)));
+ return true;
}
- }
- edgeNormal = Vector2.normalize(edgeNormal);
- return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal };
- };
- Polygon.prototype.pointCollidesWithShape = function (point) {
- return ShapeCollisions.pointToPoly(point, this);
- };
- Polygon.prototype.containsPoint = function (point) {
- point = Vector2.subtract(point, this.position);
- var isInside = false;
- for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) {
- if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) &&
- (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) +
- this.points[i].x)) {
- isInside = !isInside;
+ return false;
+ };
+ ShapeCollisions.pointToBox = function (point, box, result) {
+ if (box.containsPoint(point)) {
+ result.point = box.bounds.getClosestPointOnRectangleBorderToPoint(point, result.normal);
+ result.minimumTranslationVector = es.Vector2.subtract(point, result.point);
+ return true;
}
- }
- return isInside;
- };
- Polygon.buildSymmertricalPolygon = function (vertCount, radius) {
- var verts = new Array(vertCount);
- for (var i = 0; i < vertCount; i++) {
- var a = 2 * Math.PI * (i / vertCount);
- verts[i] = new Vector2(Math.cos(a), Math.sin(a) * radius);
- }
- return verts;
- };
- Polygon.prototype.recalculateBounds = function (collider) {
- this.center = collider.localOffset;
- if (collider.shouldColliderScaleAndRotateWithTransform) {
- var hasUnitScale = true;
- var tempMat = void 0;
- var combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y);
- if (collider.entity.scale != Vector2.one) {
- tempMat = Matrix2D.createScale(collider.entity.scale.x, collider.entity.scale.y);
- combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
- hasUnitScale = false;
- var scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale);
- this.center = scaledOffset;
+ return false;
+ };
+ ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) {
+ var v = es.Vector2.subtract(lineB, lineA);
+ var w = es.Vector2.subtract(closestTo, lineA);
+ var t = es.Vector2.dot(w, v) / es.Vector2.dot(v, v);
+ t = es.MathHelper.clamp(t, 0, 1);
+ return es.Vector2.add(lineA, es.Vector2.multiply(v, new es.Vector2(t, t)));
+ };
+ ShapeCollisions.pointToPoly = function (point, poly, result) {
+ if (poly.containsPoint(point)) {
+ var distanceSquared = 0;
+ var closestPoint = es.Polygon.getClosestPointOnPolygonToPoint(poly.points, es.Vector2.subtract(point, poly.position), distanceSquared, result.normal);
+ result.minimumTranslationVector = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared)));
+ result.point = es.Vector2.add(closestPoint, poly.position);
+ return true;
}
- if (collider.entity.rotation != 0) {
- tempMat = Matrix2D.createRotation(collider.entity.rotation, tempMat);
- combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
- var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg;
- var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length();
- this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle);
+ return false;
+ };
+ ShapeCollisions.circleToCircle = function (first, second, result) {
+ var distanceSquared = es.Vector2.distanceSquared(first.position, second.position);
+ var sumOfRadii = first.radius + second.radius;
+ var collided = distanceSquared < sumOfRadii * sumOfRadii;
+ if (collided) {
+ result.normal = es.Vector2.normalize(es.Vector2.subtract(first.position, second.position));
+ var depth = sumOfRadii - Math.sqrt(distanceSquared);
+ result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-depth), result.normal);
+ result.point = es.Vector2.add(second.position, es.Vector2.multiply(result.normal, new es.Vector2(second.radius)));
+ return true;
}
- tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y);
- combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
- Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points);
- this.isUnrotated = collider.entity.rotation == 0;
- }
- this.position = Vector2.add(collider.entity.position, this.center);
- this.bounds = Rectangle.rectEncompassingPoints(this.points);
- this.bounds.location = Vector2.add(this.bounds.location, this.position);
- };
- return Polygon;
-}(Shape));
-var Box = (function (_super) {
- __extends(Box, _super);
- function Box(width, height) {
- var _this = _super.call(this, Box.buildBox(width, height), true) || this;
- _this.width = width;
- _this.height = height;
- return _this;
- }
- Box.buildBox = function (width, height) {
- var halfWidth = width / 2;
- var halfHeight = height / 2;
- var verts = new Array(4);
- verts[0] = new Vector2(-halfWidth, -halfHeight);
- verts[1] = new Vector2(halfWidth, -halfHeight);
- verts[2] = new Vector2(halfWidth, halfHeight);
- verts[3] = new Vector2(-halfWidth, halfHeight);
- return verts;
- };
- Box.prototype.overlaps = function (other) {
- if (this.isUnrotated) {
- if (other instanceof Box && other.isUnrotated)
- return this.bounds.intersects(other.bounds);
- if (other instanceof Circle)
- return Collisions.isRectToCircle(this.bounds, other.position, other.radius);
- }
- return _super.prototype.overlaps.call(this, other);
- };
- Box.prototype.collidesWithShape = function (other) {
- if (this.isUnrotated && other instanceof Box && other.isUnrotated) {
- return ShapeCollisions.boxToBox(this, other);
- }
- return _super.prototype.collidesWithShape.call(this, other);
- };
- Box.prototype.updateBox = function (width, height) {
- this.width = width;
- this.height = height;
- var halfWidth = width / 2;
- var halfHeight = height / 2;
- this.points[0] = new Vector2(-halfWidth, -halfHeight);
- this.points[1] = new Vector2(halfWidth, -halfHeight);
- this.points[2] = new Vector2(halfWidth, halfHeight);
- this.points[3] = new Vector2(-halfWidth, halfHeight);
- for (var i = 0; i < this.points.length; i++)
- this._originalPoints[i] = this.points[i];
- };
- Box.prototype.containsPoint = function (point) {
- if (this.isUnrotated)
- return this.bounds.containsInVec(point);
- return _super.prototype.containsPoint.call(this, point);
- };
- return Box;
-}(Polygon));
-var Circle = (function (_super) {
- __extends(Circle, _super);
- function Circle(radius) {
- var _this = _super.call(this) || this;
- _this.radius = radius;
- _this._originalRadius = radius;
- return _this;
- }
- Circle.prototype.pointCollidesWithShape = function (point) {
- return ShapeCollisions.pointToCircle(point, this);
- };
- Circle.prototype.collidesWithShape = function (other) {
- if (other instanceof Box && other.isUnrotated) {
- return ShapeCollisions.circleToBox(this, other);
- }
- if (other instanceof Circle) {
- return ShapeCollisions.circleToCircle(this, other);
- }
- if (other instanceof Polygon) {
- return ShapeCollisions.circleToPolygon(this, other);
- }
- throw new Error("Collisions of Circle to " + other + " are not supported");
- };
- Circle.prototype.recalculateBounds = function (collider) {
- this.center = collider.localOffset;
- if (collider.shouldColliderScaleAndRotateWithTransform) {
- var scale = collider.entity.scale;
- var hasUnitScale = scale.x == 1 && scale.y == 1;
- var maxScale = Math.max(scale.x, scale.y);
- this.radius = this._originalRadius * maxScale;
- if (collider.entity.rotation != 0) {
- var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg;
- var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length();
- this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle);
+ return false;
+ };
+ ShapeCollisions.boxToBox = function (first, second, result) {
+ var minkowskiDiff = this.minkowskiDifference(first, second);
+ if (minkowskiDiff.contains(0, 0)) {
+ result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin();
+ if (result.minimumTranslationVector.equals(es.Vector2.zero))
+ return false;
+ result.normal = new es.Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y);
+ result.normal = result.normal.normalize();
+ return true;
}
- }
- this.position = Vector2.add(collider.entity.position, this.center);
- this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2);
- };
- Circle.prototype.overlaps = function (other) {
- if (other instanceof Box && other.isUnrotated)
- return Collisions.isRectToCircle(other.bounds, this.position, this.radius);
- if (other instanceof Circle)
- return Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius);
- if (other instanceof Polygon)
- return ShapeCollisions.circleToPolygon(this, other);
- throw new Error("overlaps of circle to " + other + " are not supported");
- };
- return Circle;
-}(Shape));
-var CollisionResult = (function () {
- function CollisionResult() {
- this.minimumTranslationVector = Vector2.zero;
- this.normal = Vector2.zero;
- this.point = Vector2.zero;
- }
- CollisionResult.prototype.invertResult = function () {
- this.minimumTranslationVector = Vector2.negate(this.minimumTranslationVector);
- this.normal = Vector2.negate(this.normal);
- };
- return CollisionResult;
-}());
-var ShapeCollisions = (function () {
- function ShapeCollisions() {
- }
- ShapeCollisions.polygonToPolygon = function (first, second) {
- var result = new CollisionResult();
- var isIntersecting = true;
- var firstEdges = first.edgeNormals;
- var secondEdges = second.edgeNormals;
- var minIntervalDistance = Number.POSITIVE_INFINITY;
- var translationAxis = new Vector2();
- var polygonOffset = Vector2.subtract(first.position, second.position);
- var axis;
- for (var edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) {
- if (edgeIndex < firstEdges.length) {
- axis = firstEdges[edgeIndex];
- }
- else {
- axis = secondEdges[edgeIndex - firstEdges.length];
- }
- var minA = 0;
- var minB = 0;
- var maxA = 0;
- var maxB = 0;
- var intervalDist = 0;
- var ta = this.getInterval(axis, first, minA, maxA);
- minA = ta.min;
- minB = ta.max;
- var tb = this.getInterval(axis, second, minB, maxB);
- minB = tb.min;
- maxB = tb.max;
- var relativeIntervalOffset = Vector2.dot(polygonOffset, axis);
- minA += relativeIntervalOffset;
- maxA += relativeIntervalOffset;
- intervalDist = this.intervalDistance(minA, maxA, minB, maxB);
- if (intervalDist > 0)
- isIntersecting = false;
- if (!isIntersecting)
- return null;
- intervalDist = Math.abs(intervalDist);
- if (intervalDist < minIntervalDistance) {
- minIntervalDistance = intervalDist;
- translationAxis = axis;
- if (Vector2.dot(translationAxis, polygonOffset) < 0)
- translationAxis = new Vector2(-translationAxis);
- }
- }
- result.normal = translationAxis;
- result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance));
- return result;
- };
- ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) {
- if (minA < minB)
- return minB - maxA;
- return minA - minB;
- };
- ShapeCollisions.getInterval = function (axis, polygon, min, max) {
- var dot = Vector2.dot(polygon.points[0], axis);
- min = max = dot;
- for (var i = 1; i < polygon.points.length; i++) {
- dot = Vector2.dot(polygon.points[i], axis);
- if (dot < min) {
- min = dot;
- }
- else if (dot > max) {
- max = dot;
- }
- }
- return { min: min, max: max };
- };
- ShapeCollisions.circleToPolygon = function (circle, polygon) {
- var result = new CollisionResult();
- var poly2Circle = Vector2.subtract(circle.position, polygon.position);
- var gpp = Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle);
- var closestPoint = gpp.closestPoint;
- var distanceSquared = gpp.distanceSquared;
- result.normal = gpp.edgeNormal;
- var circleCenterInsidePoly = polygon.containsPoint(circle.position);
- if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly)
- return null;
- var mtv;
- if (circleCenterInsidePoly) {
- mtv = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared) - circle.radius));
- }
- else {
- if (distanceSquared == 0) {
- mtv = Vector2.multiply(result.normal, new Vector2(circle.radius));
- }
- else {
- var distance = Math.sqrt(distanceSquared);
- mtv = Vector2.multiply(new Vector2(-Vector2.subtract(poly2Circle, closestPoint)), new Vector2((circle.radius - distanceSquared) / distance));
- }
- }
- result.minimumTranslationVector = mtv;
- result.point = Vector2.add(closestPoint, polygon.position);
- return result;
- };
- ShapeCollisions.circleToBox = function (circle, box) {
- var result = new CollisionResult();
- var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res;
- if (box.containsPoint(circle.position)) {
- result.point = closestPointOnBounds;
- var safePlace = Vector2.add(closestPointOnBounds, Vector2.subtract(result.normal, new Vector2(circle.radius)));
- result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace);
- return result;
- }
- var sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position);
- if (sqrDistance == 0) {
- result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(circle.radius));
- }
- else if (sqrDistance <= circle.radius * circle.radius) {
- result.normal = Vector2.subtract(circle.position, closestPointOnBounds);
- var depth = result.normal.length() - circle.radius;
- result.normal = Vector2Ext.normalize(result.normal);
- result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal);
- return result;
- }
- return null;
- };
- ShapeCollisions.pointToCircle = function (point, circle) {
- var result = new CollisionResult();
- var distanceSquared = Vector2.distanceSquared(point, circle.position);
- var sumOfRadii = 1 + circle.radius;
- var collided = distanceSquared < sumOfRadii * sumOfRadii;
- if (collided) {
- result.normal = Vector2.normalize(Vector2.subtract(point, circle.position));
- var depth = sumOfRadii - Math.sqrt(distanceSquared);
- result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth, -depth), result.normal);
- result.point = Vector2.add(circle.position, Vector2.multiply(result.normal, new Vector2(circle.radius, circle.radius)));
- return result;
- }
- return null;
- };
- ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) {
- var v = Vector2.subtract(lineB, lineA);
- var w = Vector2.subtract(closestTo, lineA);
- var t = Vector2.dot(w, v) / Vector2.dot(v, v);
- t = MathHelper.clamp(t, 0, 1);
- return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t, t)));
- };
- ShapeCollisions.pointToPoly = function (point, poly) {
- var result = new CollisionResult();
- if (poly.containsPoint(point)) {
- var distanceSquared = void 0;
- var gpp = Polygon.getClosestPointOnPolygonToPoint(poly.points, Vector2.subtract(point, poly.position));
- var closestPoint = gpp.closestPoint;
- distanceSquared = gpp.distanceSquared;
- result.normal = gpp.edgeNormal;
- result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared)));
- result.point = Vector2.add(closestPoint, poly.position);
- return result;
- }
- return null;
- };
- ShapeCollisions.circleToCircle = function (first, second) {
- var result = new CollisionResult();
- var distanceSquared = Vector2.distanceSquared(first.position, second.position);
- var sumOfRadii = first.radius + second.radius;
- var collided = distanceSquared < sumOfRadii * sumOfRadii;
- if (collided) {
- result.normal = Vector2.normalize(Vector2.subtract(first.position, second.position));
- var depth = sumOfRadii - Math.sqrt(distanceSquared);
- result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth), result.normal);
- result.point = Vector2.add(second.position, Vector2.multiply(result.normal, new Vector2(second.radius)));
- return result;
- }
- return null;
- };
- ShapeCollisions.boxToBox = function (first, second) {
- var result = new CollisionResult();
- var minkowskiDiff = this.minkowskiDifference(first, second);
- if (minkowskiDiff.containsInVec(new Vector2(0, 0))) {
- result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin();
- if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0)
- return null;
- result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y);
- result.normal.normalize();
- return result;
- }
- return null;
- };
- ShapeCollisions.minkowskiDifference = function (first, second) {
- var positionOffset = Vector2.subtract(first.position, Vector2.add(first.bounds.location, Vector2.divide(first.bounds.size, new Vector2(2))));
- var topLeft = Vector2.subtract(Vector2.add(first.bounds.location, positionOffset), second.bounds.max);
- var fullSize = Vector2.add(first.bounds.size, second.bounds.size);
- return new Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y);
- };
- return ShapeCollisions;
-}());
-var SpatialHash = (function () {
- function SpatialHash(cellSize) {
- if (cellSize === void 0) { cellSize = 100; }
- this.gridBounds = new Rectangle();
- this._overlapTestCircle = new Circle(0);
- this._tempHashSet = [];
- this._cellDict = new NumberDictionary();
- this._cellSize = cellSize;
- this._inverseCellSize = 1 / this._cellSize;
- this._raycastParser = new RaycastResultParser();
- }
- SpatialHash.prototype.remove = function (collider) {
- var bounds = collider.registeredPhysicsBounds;
- var p1 = this.cellCoords(bounds.x, bounds.y);
- var p2 = this.cellCoords(bounds.right, bounds.bottom);
- for (var x = p1.x; x <= p2.x; x++) {
- for (var y = p1.y; y <= p2.y; y++) {
- var cell = this.cellAtPosition(x, y);
- if (!cell)
- console.error("removing Collider [" + collider + "] from a cell that it is not present in");
- else
- cell.remove(collider);
- }
- }
- };
- SpatialHash.prototype.register = function (collider) {
- var bounds = collider.bounds;
- collider.registeredPhysicsBounds = bounds;
- var p1 = this.cellCoords(bounds.x, bounds.y);
- var p2 = this.cellCoords(bounds.right, bounds.bottom);
- if (!this.gridBounds.containsInVec(new Vector2(p1.x, p1.y))) {
- this.gridBounds = RectangleExt.union(this.gridBounds, p1);
- }
- if (!this.gridBounds.containsInVec(new Vector2(p2.x, p2.y))) {
- this.gridBounds = RectangleExt.union(this.gridBounds, p2);
- }
- for (var x = p1.x; x <= p2.x; x++) {
- for (var y = p1.y; y <= p2.y; y++) {
- var c = this.cellAtPosition(x, y, true);
- c.push(collider);
- }
- }
- };
- SpatialHash.prototype.clear = function () {
- this._cellDict.clear();
- };
- SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) {
- var bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2);
- this._overlapTestCircle.radius = radius;
- this._overlapTestCircle.position = circleCenter;
- var resultCounter = 0;
- var aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask);
- bounds = aabbBroadphaseResult.bounds;
- var potentials = aabbBroadphaseResult.tempHashSet;
- for (var i = 0; i < potentials.length; i++) {
- var collider = potentials[i];
- if (collider instanceof BoxCollider) {
- results[resultCounter] = collider;
- resultCounter++;
- }
- else {
- throw new Error("overlapCircle against this collider type is not implemented!");
- }
- if (resultCounter == results.length)
- return resultCounter;
- }
- return resultCounter;
- };
- SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) {
- this._tempHashSet.length = 0;
- var p1 = this.cellCoords(bounds.x, bounds.y);
- var p2 = this.cellCoords(bounds.right, bounds.bottom);
- for (var x = p1.x; x <= p2.x; x++) {
- for (var y = p1.y; y <= p2.y; y++) {
- var cell = this.cellAtPosition(x, y);
- if (!cell)
- continue;
- for (var i = 0; i < cell.length; i++) {
- var collider = cell[i];
- if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer))
- continue;
- if (bounds.intersects(collider.bounds)) {
- if (this._tempHashSet.indexOf(collider) == -1)
- this._tempHashSet.push(collider);
+ return false;
+ };
+ ShapeCollisions.minkowskiDifference = function (first, second) {
+ var positionOffset = es.Vector2.subtract(first.position, es.Vector2.add(first.bounds.location, es.Vector2.divide(first.bounds.size, new es.Vector2(2))));
+ var topLeft = es.Vector2.subtract(es.Vector2.add(first.bounds.location, positionOffset), second.bounds.max);
+ var fullSize = es.Vector2.add(first.bounds.size, second.bounds.size);
+ return new es.Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y);
+ };
+ ShapeCollisions.lineToPoly = function (start, end, polygon, hit) {
+ var normal = es.Vector2.zero;
+ var intersectionPoint = es.Vector2.zero;
+ var fraction = Number.MAX_VALUE;
+ var hasIntersection = false;
+ for (var j = polygon.points.length - 1, i = 0; i < polygon.points.length; j = i, i++) {
+ var edge1 = es.Vector2.add(polygon.position, polygon.points[j]);
+ var edge2 = es.Vector2.add(polygon.position, polygon.points[i]);
+ var intersection = es.Vector2.zero;
+ if (this.lineToLine(edge1, edge2, start, end, intersection)) {
+ hasIntersection = true;
+ var distanceFraction = (intersection.x - start.x) / (end.x - start.x);
+ if (Number.isNaN(distanceFraction) || Number.isFinite(distanceFraction))
+ distanceFraction = (intersection.y - start.y) / (end.y - start.y);
+ if (distanceFraction < fraction) {
+ var edge = es.Vector2.subtract(edge2, edge1);
+ normal = new es.Vector2(edge.y, -edge.x);
+ fraction = distanceFraction;
+ intersectionPoint = intersection;
}
}
}
- }
- return { tempHashSet: this._tempHashSet, bounds: bounds };
- };
- SpatialHash.prototype.cellAtPosition = function (x, y, createCellIfEmpty) {
- if (createCellIfEmpty === void 0) { createCellIfEmpty = false; }
- var cell = this._cellDict.tryGetValue(x, y);
- if (!cell) {
- if (createCellIfEmpty) {
- cell = [];
- this._cellDict.add(x, y, cell);
+ if (hasIntersection) {
+ normal = normal.normalize();
+ var distance = es.Vector2.distance(start, intersectionPoint);
+ hit.setValuesNonCollider(fraction, distance, intersectionPoint, normal);
+ return true;
}
- }
- return cell;
- };
- SpatialHash.prototype.cellCoords = function (x, y) {
- return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
- };
- return SpatialHash;
-}());
-var RaycastResultParser = (function () {
- function RaycastResultParser() {
- }
- return RaycastResultParser;
-}());
-var NumberDictionary = (function () {
- function NumberDictionary() {
- this._store = new Map();
- }
- NumberDictionary.prototype.getKey = function (x, y) {
- return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString();
- };
- NumberDictionary.prototype.intToUint = function (i) {
- if (i >= 0)
- return i;
- else
- return 4294967296 + i;
- };
- NumberDictionary.prototype.add = function (x, y, list) {
- this._store.set(this.getKey(x, y), list);
- };
- NumberDictionary.prototype.remove = function (obj) {
- this._store.forEach(function (list) {
- if (list.contains(obj))
- list.remove(obj);
- });
- };
- NumberDictionary.prototype.tryGetValue = function (x, y) {
- return this._store.get(this.getKey(x, y));
- };
- NumberDictionary.prototype.clear = function () {
- this._store.clear();
- };
- return NumberDictionary;
-}());
-var ContentManager = (function () {
- function ContentManager() {
- this.loadedAssets = new Map();
- }
- ContentManager.prototype.loadRes = function (name, local) {
- var _this = this;
- if (local === void 0) { local = true; }
- return new Promise(function (resolve, reject) {
- var res = _this.loadedAssets.get(name);
- if (res) {
- resolve(res);
- return;
- }
- if (local) {
- RES.getResAsync(name).then(function (data) {
- _this.loadedAssets.set(name, data);
- resolve(data);
- }).catch(function (err) {
- console.error("资源加载错误:", name, err);
- reject(err);
- });
+ return false;
+ };
+ ShapeCollisions.lineToLine = function (a1, a2, b1, b2, intersection) {
+ var b = es.Vector2.subtract(a2, a1);
+ var d = es.Vector2.subtract(b2, b1);
+ var bDotDPerp = b.x * d.y - b.y * d.x;
+ if (bDotDPerp == 0)
+ return false;
+ var c = es.Vector2.subtract(b1, a1);
+ var t = (c.x * d.y - c.y * d.x) / bDotDPerp;
+ if (t < 0 || t > 1)
+ return false;
+ var u = (c.x * b.y - c.y * b.x) / bDotDPerp;
+ if (u < 0 || u > 1)
+ return false;
+ intersection = intersection.add(a1).add(es.Vector2.multiply(new es.Vector2(t), b));
+ return true;
+ };
+ ShapeCollisions.lineToCircle = function (start, end, s, hit) {
+ var lineLength = es.Vector2.distance(start, end);
+ var d = es.Vector2.divide(es.Vector2.subtract(end, start), new es.Vector2(lineLength));
+ var m = es.Vector2.subtract(start, s.position);
+ var b = es.Vector2.dot(m, d);
+ var c = es.Vector2.dot(m, m) - s.radius * s.radius;
+ if (c > 0 && b > 0)
+ return false;
+ var discr = b * b - c;
+ if (discr < 0)
+ return false;
+ hit.fraction = -b - Math.sqrt(discr);
+ if (hit.fraction < 0)
+ hit.fraction = 0;
+ hit.point = es.Vector2.add(start, es.Vector2.multiply(new es.Vector2(hit.fraction), d));
+ hit.distance = es.Vector2.distance(start, hit.point);
+ hit.normal = es.Vector2.normalize(es.Vector2.subtract(hit.point, s.position));
+ hit.fraction = hit.distance / lineLength;
+ return true;
+ };
+ ShapeCollisions.boxToBoxCast = function (first, second, movement, hit) {
+ var minkowskiDiff = this.minkowskiDifference(first, second);
+ if (minkowskiDiff.contains(0, 0)) {
+ var mtv = minkowskiDiff.getClosestPointOnBoundsToOrigin();
+ if (mtv.equals(es.Vector2.zero))
+ return false;
+ hit.normal = new es.Vector2(-mtv.x);
+ hit.normal = hit.normal.normalize();
+ hit.distance = 0;
+ hit.fraction = 0;
+ return true;
}
else {
- RES.getResByUrl(name).then(function (data) {
- _this.loadedAssets.set(name, data);
- resolve(data);
- }).catch(function (err) {
- console.error("资源加载错误:", name, err);
- reject(err);
- });
+ var ray = new es.Ray2D(es.Vector2.zero, new es.Vector2(-movement.x));
+ var fraction = minkowskiDiff.rayIntersects(ray);
+ if (fraction <= 1) {
+ hit.fraction = fraction;
+ hit.distance = movement.length() * fraction;
+ hit.normal = new es.Vector2(-movement.x);
+ hit.normal = hit.normal.normalize();
+ hit.centroid = es.Vector2.add(first.bounds.center, es.Vector2.multiply(movement, new es.Vector2(fraction)));
+ return true;
+ }
}
- });
- };
- ContentManager.prototype.dispose = function () {
- this.loadedAssets.forEach(function (value) {
- var assetsToRemove = value;
- assetsToRemove.dispose();
- });
- this.loadedAssets.clear();
- };
- return ContentManager;
-}());
-var Emitter = (function () {
- function Emitter() {
- this._messageTable = new Map();
+ return false;
+ };
+ return ShapeCollisions;
+ }());
+ es.ShapeCollisions = ShapeCollisions;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var SpatialHash = (function () {
+ function SpatialHash(cellSize) {
+ if (cellSize === void 0) { cellSize = 100; }
+ this.gridBounds = new es.Rectangle();
+ this._overlapTestCircle = new es.Circle(0);
+ this._cellDict = new NumberDictionary();
+ this._tempHashSet = [];
+ this._cellSize = cellSize;
+ this._inverseCellSize = 1 / this._cellSize;
+ this._raycastParser = new RaycastResultParser();
+ }
+ SpatialHash.prototype.register = function (collider) {
+ var bounds = collider.bounds;
+ collider.registeredPhysicsBounds = bounds;
+ var p1 = this.cellCoords(bounds.x, bounds.y);
+ var p2 = this.cellCoords(bounds.right, bounds.bottom);
+ if (!this.gridBounds.contains(p1.x, p1.y)) {
+ this.gridBounds = es.RectangleExt.union(this.gridBounds, p1);
+ }
+ if (!this.gridBounds.contains(p2.x, p2.y)) {
+ this.gridBounds = es.RectangleExt.union(this.gridBounds, p2);
+ }
+ for (var x = p1.x; x <= p2.x; x++) {
+ for (var y = p1.y; y <= p2.y; y++) {
+ var c = this.cellAtPosition(x, y, true);
+ if (!c.firstOrDefault(function (c) { return c.hashCode == collider.hashCode; }))
+ c.push(collider);
+ }
+ }
+ };
+ SpatialHash.prototype.remove = function (collider) {
+ var bounds = collider.registeredPhysicsBounds;
+ var p1 = this.cellCoords(bounds.x, bounds.y);
+ var p2 = this.cellCoords(bounds.right, bounds.bottom);
+ for (var x = p1.x; x <= p2.x; x++) {
+ for (var y = p1.y; y <= p2.y; y++) {
+ var cell = this.cellAtPosition(x, y);
+ if (!cell)
+ console.error("removing Collider [" + collider + "] from a cell that it is not present in");
+ else
+ cell.remove(collider);
+ }
+ }
+ };
+ SpatialHash.prototype.removeWithBruteForce = function (obj) {
+ this._cellDict.remove(obj);
+ };
+ SpatialHash.prototype.clear = function () {
+ this._cellDict.clear();
+ };
+ SpatialHash.prototype.debugDraw = function (secondsToDisplay, textScale) {
+ if (textScale === void 0) { textScale = 1; }
+ for (var x = this.gridBounds.x; x <= this.gridBounds.right; x++) {
+ for (var y = this.gridBounds.y; y <= this.gridBounds.bottom; y++) {
+ var cell = this.cellAtPosition(x, y);
+ if (cell && cell.length > 0)
+ this.debugDrawCellDetails(x, y, cell.length, secondsToDisplay, textScale);
+ }
+ }
+ };
+ SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) {
+ this._tempHashSet.length = 0;
+ var p1 = this.cellCoords(bounds.x, bounds.y);
+ var p2 = this.cellCoords(bounds.right, bounds.bottom);
+ for (var x = p1.x; x <= p2.x; x++) {
+ for (var y = p1.y; y <= p2.y; y++) {
+ var cell = this.cellAtPosition(x, y);
+ if (!cell)
+ continue;
+ var _loop_7 = function (i) {
+ var collider = cell[i];
+ if (collider == excludeCollider || !es.Flags.isFlagSet(layerMask, collider.physicsLayer))
+ return "continue";
+ if (bounds.intersects(collider.bounds)) {
+ if (!this_3._tempHashSet.firstOrDefault(function (c) { return c.hashCode == collider.hashCode; }))
+ this_3._tempHashSet.push(collider);
+ }
+ };
+ var this_3 = this;
+ for (var i = 0; i < cell.length; i++) {
+ _loop_7(i);
+ }
+ }
+ }
+ return this._tempHashSet;
+ };
+ SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) {
+ var bounds = new es.Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2);
+ this._overlapTestCircle.radius = radius;
+ this._overlapTestCircle.position = circleCenter;
+ var resultCounter = 0;
+ var potentials = this.aabbBroadphase(bounds, null, layerMask);
+ for (var i = 0; i < potentials.length; i++) {
+ var collider = potentials[i];
+ if (collider instanceof es.BoxCollider) {
+ results[resultCounter] = collider;
+ resultCounter++;
+ }
+ else if (collider instanceof es.CircleCollider) {
+ if (collider.shape.overlaps(this._overlapTestCircle)) {
+ results[resultCounter] = collider;
+ resultCounter++;
+ }
+ }
+ else if (collider instanceof es.PolygonCollider) {
+ if (collider.shape.overlaps(this._overlapTestCircle)) {
+ results[resultCounter] = collider;
+ resultCounter++;
+ }
+ }
+ else {
+ throw new Error("overlapCircle against this collider type is not implemented!");
+ }
+ if (resultCounter == results.length)
+ return resultCounter;
+ }
+ return resultCounter;
+ };
+ SpatialHash.prototype.cellCoords = function (x, y) {
+ return new es.Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
+ };
+ SpatialHash.prototype.cellAtPosition = function (x, y, createCellIfEmpty) {
+ if (createCellIfEmpty === void 0) { createCellIfEmpty = false; }
+ var cell = this._cellDict.tryGetValue(x, y);
+ if (!cell) {
+ if (createCellIfEmpty) {
+ cell = [];
+ this._cellDict.add(x, y, cell);
+ }
+ }
+ return cell;
+ };
+ SpatialHash.prototype.debugDrawCellDetails = function (x, y, cellCount, secondsToDisplay, textScale) {
+ if (secondsToDisplay === void 0) { secondsToDisplay = 0.5; }
+ if (textScale === void 0) { textScale = 1; }
+ };
+ return SpatialHash;
+ }());
+ es.SpatialHash = SpatialHash;
+ var NumberDictionary = (function () {
+ function NumberDictionary() {
+ this._store = new Map();
+ }
+ NumberDictionary.prototype.add = function (x, y, list) {
+ this._store.set(this.getKey(x, y), list);
+ };
+ NumberDictionary.prototype.remove = function (obj) {
+ this._store.forEach(function (list) {
+ if (list.contains(obj))
+ list.remove(obj);
+ });
+ };
+ NumberDictionary.prototype.tryGetValue = function (x, y) {
+ return this._store.get(this.getKey(x, y));
+ };
+ NumberDictionary.prototype.clear = function () {
+ this._store.clear();
+ };
+ NumberDictionary.prototype.getKey = function (x, y) {
+ return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, true)).toString();
+ };
+ return NumberDictionary;
+ }());
+ es.NumberDictionary = NumberDictionary;
+ var RaycastResultParser = (function () {
+ function RaycastResultParser() {
+ this._checkedColliders = [];
+ this._cellHits = [];
+ }
+ RaycastResultParser.prototype.start = function (ray, hits, layerMask) {
+ this._ray = ray;
+ this._hits = hits;
+ this._layerMask = layerMask;
+ this.hitCounter = 0;
+ };
+ RaycastResultParser.prototype.checkRayIntersection = function (cellX, cellY, cell) {
+ var fraction = 0;
+ for (var i = 0; i < cell.length; i++) {
+ var potential = cell[i];
+ if (this._checkedColliders.contains(potential))
+ continue;
+ this._checkedColliders.push(potential);
+ if (potential.isTrigger && !es.Physics.raycastsHitTriggers)
+ continue;
+ if (!es.Flags.isFlagSet(this._layerMask, potential.physicsLayer))
+ continue;
+ var colliderBounds = potential.bounds;
+ var fraction_1 = colliderBounds.rayIntersects(this._ray);
+ if (fraction_1 <= 1) {
+ if (potential.shape.collidesWithLine(this._ray.start, this._ray.end, this._tempHit)) {
+ if (!es.Physics.raycastsStartInColliders && potential.shape.containsPoint(this._ray.start))
+ continue;
+ this._tempHit.collider = potential;
+ this._cellHits.push(this._tempHit);
+ }
+ }
+ }
+ if (this._cellHits.length == 0)
+ return false;
+ this._cellHits.sort(RaycastResultParser.compareRaycastHits);
+ for (var i = 0; i < this._cellHits.length; i++) {
+ this._hits[this.hitCounter] = this._cellHits[i];
+ this.hitCounter++;
+ if (this.hitCounter == this._hits.length)
+ return true;
+ }
+ return false;
+ };
+ RaycastResultParser.prototype.reset = function () {
+ this._hits = null;
+ this._checkedColliders.length = 0;
+ this._cellHits.length = 0;
+ };
+ RaycastResultParser.compareRaycastHits = function (a, b) {
+ return a.distance - b.distance;
+ };
+ return RaycastResultParser;
+ }());
+ es.RaycastResultParser = RaycastResultParser;
+})(es || (es = {}));
+var ArrayUtils = (function () {
+ function ArrayUtils() {
}
- Emitter.prototype.addObserver = function (eventType, handler) {
- var list = this._messageTable.get(eventType);
- if (!list) {
- list = [];
- this._messageTable.set(eventType, list);
- }
- if (list.contains(handler))
- console.warn("您试图添加相同的观察者两次");
- list.push(handler);
- };
- Emitter.prototype.removeObserver = function (eventType, handler) {
- this._messageTable.get(eventType).remove(handler);
- };
- Emitter.prototype.emit = function (eventType, data) {
- var list = this._messageTable.get(eventType);
- if (list) {
- for (var i = list.length - 1; i >= 0; i--)
- list[i](data);
- }
- };
- return Emitter;
-}());
-var GlobalManager = (function () {
- function GlobalManager() {
- }
- Object.defineProperty(GlobalManager.prototype, "enabled", {
- get: function () {
- return this._enabled;
- },
- set: function (value) {
- this.setEnabled(value);
- },
- enumerable: true,
- configurable: true
- });
- GlobalManager.prototype.setEnabled = function (isEnabled) {
- if (this._enabled != isEnabled) {
- this._enabled = isEnabled;
- if (this._enabled) {
- this.onEnabled();
- }
- else {
- this.onDisabled();
+ ArrayUtils.bubbleSort = function (ary) {
+ var isExchange = false;
+ for (var i = 0; i < ary.length; i++) {
+ isExchange = false;
+ for (var j = ary.length - 1; j > i; j--) {
+ if (ary[j] < ary[j - 1]) {
+ var temp = ary[j];
+ ary[j] = ary[j - 1];
+ ary[j - 1] = temp;
+ isExchange = true;
+ }
}
+ if (!isExchange)
+ break;
}
};
- GlobalManager.prototype.onEnabled = function () { };
- GlobalManager.prototype.onDisabled = function () { };
- GlobalManager.prototype.update = function () { };
- GlobalManager.registerGlobalManager = function (manager) {
- this.globalManagers.push(manager);
- manager.enabled = true;
+ ArrayUtils.insertionSort = function (ary) {
+ var len = ary.length;
+ for (var i = 1; i < len; i++) {
+ var val = ary[i];
+ for (var j = i; j > 0 && ary[j - 1] > val; j--) {
+ ary[j] = ary[j - 1];
+ }
+ ary[j] = val;
+ }
};
- GlobalManager.unregisterGlobalManager = function (manager) {
- this.globalManagers.remove(manager);
- manager.enabled = false;
+ ArrayUtils.binarySearch = function (ary, value) {
+ var startIndex = 0;
+ var endIndex = ary.length;
+ var sub = (startIndex + endIndex) >> 1;
+ while (startIndex < endIndex) {
+ if (value <= ary[sub])
+ endIndex = sub;
+ else if (value >= ary[sub])
+ startIndex = sub + 1;
+ sub = (startIndex + endIndex) >> 1;
+ }
+ if (ary[startIndex] == value)
+ return startIndex;
+ return -1;
};
- GlobalManager.getGlobalManager = function (type) {
- for (var i = 0; i < this.globalManagers.length; i++) {
- if (this.globalManagers[i] instanceof type)
- return this.globalManagers[i];
+ ArrayUtils.findElementIndex = function (ary, num) {
+ var len = ary.length;
+ for (var i = 0; i < len; ++i) {
+ if (ary[i] == num)
+ return i;
}
return null;
};
- GlobalManager.globalManagers = [];
- return GlobalManager;
-}());
-var TouchState = (function () {
- function TouchState() {
- this.x = 0;
- this.y = 0;
- this.touchPoint = -1;
- this.touchDown = false;
- }
- Object.defineProperty(TouchState.prototype, "position", {
- get: function () {
- return new Vector2(this.x, this.y);
- },
- enumerable: true,
- configurable: true
- });
- TouchState.prototype.reset = function () {
- this.x = 0;
- this.y = 0;
- this.touchDown = false;
- this.touchPoint = -1;
+ ArrayUtils.getMaxElementIndex = function (ary) {
+ var matchIndex = 0;
+ var len = ary.length;
+ for (var j = 1; j < len; j++) {
+ if (ary[j] > ary[matchIndex])
+ matchIndex = j;
+ }
+ return matchIndex;
};
- return TouchState;
-}());
-var Input = (function () {
- function Input() {
- }
- Object.defineProperty(Input, "touchPosition", {
- get: function () {
- if (!this._gameTouchs[0])
- return Vector2.zero;
- return this._gameTouchs[0].position;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Input, "maxSupportedTouch", {
- get: function () {
- return this._stage.maxTouches;
- },
- set: function (value) {
- this._stage.maxTouches = value;
- this.initTouchCache();
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Input, "resolutionScale", {
- get: function () {
- return this._resolutionScale;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Input, "totalTouchCount", {
- get: function () {
- return this._totalTouchCount;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Input, "gameTouchs", {
- get: function () {
- return this._gameTouchs;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Input, "touchPositionDelta", {
- get: function () {
- var delta = Vector2.subtract(this.touchPosition, this._previousTouchState.position);
- if (delta.length() > 0) {
- this.setpreviousTouchState(this._gameTouchs[0]);
+ ArrayUtils.getMinElementIndex = function (ary) {
+ var matchIndex = 0;
+ var len = ary.length;
+ for (var j = 1; j < len; j++) {
+ if (ary[j] < ary[matchIndex])
+ matchIndex = j;
+ }
+ return matchIndex;
+ };
+ ArrayUtils.getUniqueAry = function (ary) {
+ var uAry = [];
+ var newAry = [];
+ var count = ary.length;
+ for (var i = 0; i < count; ++i) {
+ var value = ary[i];
+ if (uAry.indexOf(value) == -1)
+ uAry.push(value);
+ }
+ count = uAry.length;
+ for (var i = count - 1; i >= 0; --i) {
+ newAry.unshift(uAry[i]);
+ }
+ return newAry;
+ };
+ ArrayUtils.getDifferAry = function (aryA, aryB) {
+ aryA = this.getUniqueAry(aryA);
+ aryB = this.getUniqueAry(aryB);
+ var ary = aryA.concat(aryB);
+ var uObj = {};
+ var newAry = [];
+ var count = ary.length;
+ for (var j = 0; j < count; ++j) {
+ if (!uObj[ary[j]]) {
+ uObj[ary[j]] = {};
+ uObj[ary[j]].count = 0;
+ uObj[ary[j]].key = ary[j];
+ uObj[ary[j]].count++;
}
- return delta;
- },
- enumerable: true,
- configurable: true
- });
- Input.initialize = function (stage) {
- if (this._init)
+ else {
+ if (uObj[ary[j]] instanceof Object) {
+ uObj[ary[j]].count++;
+ }
+ }
+ }
+ for (var i in uObj) {
+ if (uObj[i].count != 2) {
+ newAry.unshift(uObj[i].key);
+ }
+ }
+ return newAry;
+ };
+ ArrayUtils.swap = function (array, index1, index2) {
+ var temp = array[index1];
+ array[index1] = array[index2];
+ array[index2] = temp;
+ };
+ ArrayUtils.clearList = function (ary) {
+ if (!ary)
return;
- this._init = true;
- this._stage = stage;
- this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
- this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this);
- this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
- this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this);
- this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this);
- this.initTouchCache();
- };
- Input.initTouchCache = function () {
- this._totalTouchCount = 0;
- this._touchIndex = 0;
- this._gameTouchs.length = 0;
- for (var i = 0; i < this.maxSupportedTouch; i++) {
- this._gameTouchs.push(new TouchState());
+ var length = ary.length;
+ for (var i = length - 1; i >= 0; i -= 1) {
+ ary.splice(i, 1);
}
};
- Input.touchBegin = function (evt) {
- if (this._touchIndex < this.maxSupportedTouch) {
- this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID;
- this._gameTouchs[this._touchIndex].touchDown = evt.touchDown;
- this._gameTouchs[this._touchIndex].x = evt.stageX;
- this._gameTouchs[this._touchIndex].y = evt.stageY;
- if (this._touchIndex == 0) {
- this.setpreviousTouchState(this._gameTouchs[0]);
- }
- this._touchIndex++;
- this._totalTouchCount++;
- }
+ ArrayUtils.cloneList = function (ary) {
+ if (!ary)
+ return null;
+ return ary.slice(0, ary.length);
};
- Input.touchMove = function (evt) {
- if (evt.touchPointID == this._gameTouchs[0].touchPoint) {
- this.setpreviousTouchState(this._gameTouchs[0]);
- }
- var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; });
- if (touchIndex != -1) {
- var touchData = this._gameTouchs[touchIndex];
- touchData.x = evt.stageX;
- touchData.y = evt.stageY;
- }
- };
- Input.touchEnd = function (evt) {
- var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; });
- if (touchIndex != -1) {
- var touchData = this._gameTouchs[touchIndex];
- touchData.reset();
- if (touchIndex == 0)
- this._previousTouchState.reset();
- this._totalTouchCount--;
- if (this.totalTouchCount == 0) {
- this._touchIndex = 0;
- }
- }
- };
- Input.setpreviousTouchState = function (touchState) {
- this._previousTouchState = new TouchState();
- this._previousTouchState.x = touchState.position.x;
- this._previousTouchState.y = touchState.position.y;
- this._previousTouchState.touchPoint = touchState.touchPoint;
- this._previousTouchState.touchDown = touchState.touchDown;
- };
- Input.scaledPosition = function (position) {
- var scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y);
- return Vector2.multiply(scaledPos, this.resolutionScale);
- };
- Input._init = false;
- Input._previousTouchState = new TouchState();
- Input._gameTouchs = [];
- Input._resolutionOffset = new Vector2();
- Input._resolutionScale = Vector2.one;
- Input._touchIndex = 0;
- Input._totalTouchCount = 0;
- return Input;
-}());
-var ListPool = (function () {
- function ListPool() {
- }
- ListPool.warmCache = function (cacheCount) {
- cacheCount -= this._objectQueue.length;
- if (cacheCount > 0) {
- for (var i = 0; i < cacheCount; i++) {
- this._objectQueue.unshift([]);
- }
- }
- };
- ListPool.trimCache = function (cacheCount) {
- while (cacheCount > this._objectQueue.length)
- this._objectQueue.shift();
- };
- ListPool.clearCache = function () {
- this._objectQueue.length = 0;
- };
- ListPool.obtain = function () {
- if (this._objectQueue.length > 0)
- return this._objectQueue.shift();
- return [];
- };
- ListPool.free = function (obj) {
- this._objectQueue.unshift(obj);
- obj.length = 0;
- };
- ListPool._objectQueue = [];
- return ListPool;
-}());
-var Pair = (function () {
- function Pair(first, second) {
- this.first = first;
- this.second = second;
- }
- Pair.prototype.clear = function () {
- this.first = this.second = null;
- };
- Pair.prototype.equals = function (other) {
- return this.first == other.first && this.second == other.second;
- };
- return Pair;
-}());
-var RectangleExt = (function () {
- function RectangleExt() {
- }
- RectangleExt.union = function (first, point) {
- var rect = new Rectangle(point.x, point.y, 0, 0);
- return this.unionR(first, rect);
- };
- RectangleExt.unionR = function (value1, value2) {
- var result = new Rectangle();
- result.x = Math.min(value1.x, value2.x);
- result.y = Math.min(value1.y, value2.y);
- result.width = Math.max(value1.right, value2.right) - result.x;
- result.height = Math.max(value1.bottom, value2.bottom) - result.y;
- return result;
- };
- return RectangleExt;
-}());
-var Triangulator = (function () {
- function Triangulator() {
- this.triangleIndices = [];
- this._triPrev = new Array(12);
- this._triNext = new Array(12);
- }
- Triangulator.prototype.triangulate = function (points, arePointsCCW) {
- if (arePointsCCW === void 0) { arePointsCCW = true; }
- var count = points.length;
- this.initialize(count);
- var iterations = 0;
- var index = 0;
- while (count > 3 && iterations < 500) {
- iterations++;
- var isEar = true;
- var a = points[this._triPrev[index]];
- var b = points[index];
- var c = points[this._triNext[index]];
- if (Vector2Ext.isTriangleCCW(a, b, c)) {
- var k = this._triNext[this._triNext[index]];
- do {
- if (Triangulator.testPointTriangle(points[k], a, b, c)) {
- isEar = false;
- break;
- }
- k = this._triNext[k];
- } while (k != this._triPrev[index]);
- }
- else {
- isEar = false;
- }
- if (isEar) {
- this.triangleIndices.push(this._triPrev[index]);
- this.triangleIndices.push(index);
- this.triangleIndices.push(this._triNext[index]);
- this._triNext[this._triPrev[index]] = this._triNext[index];
- this._triPrev[this._triNext[index]] = this._triPrev[index];
- count--;
- index = this._triPrev[index];
- }
- else {
- index = this._triNext[index];
- }
- }
- this.triangleIndices.push(this._triPrev[index]);
- this.triangleIndices.push(index);
- this.triangleIndices.push(this._triNext[index]);
- if (!arePointsCCW)
- this.triangleIndices.reverse();
- };
- Triangulator.prototype.initialize = function (count) {
- this.triangleIndices.length = 0;
- if (this._triNext.length < count) {
- this._triNext.reverse();
- this._triNext = new Array(Math.max(this._triNext.length * 2, count));
- }
- if (this._triPrev.length < count) {
- this._triPrev.reverse();
- this._triPrev = new Array(Math.max(this._triPrev.length * 2, count));
- }
- for (var i = 0; i < count; i++) {
- this._triPrev[i] = i - 1;
- this._triNext[i] = i + 1;
- }
- this._triPrev[0] = count - 1;
- this._triNext[count - 1] = 0;
- };
- Triangulator.testPointTriangle = function (point, a, b, c) {
- if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0)
- return false;
- if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0)
- return false;
- if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0)
+ ArrayUtils.equals = function (ary1, ary2) {
+ if (ary1 == ary2)
+ return true;
+ var length = ary1.length;
+ if (length != ary2.length)
return false;
+ while (length--) {
+ if (ary1[length] != ary2[length])
+ return false;
+ }
return true;
};
- return Triangulator;
-}());
-var Vector2Ext = (function () {
- function Vector2Ext() {
- }
- Vector2Ext.isTriangleCCW = function (a, center, c) {
- return this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0;
- };
- Vector2Ext.cross = function (u, v) {
- return u.y * v.x - u.x * v.y;
- };
- Vector2Ext.perpendicular = function (first, second) {
- return new Vector2(-1 * (second.y - first.y), second.x - first.x);
- };
- Vector2Ext.normalize = function (vec) {
- var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y));
- if (magnitude > MathHelper.Epsilon) {
- vec = Vector2.divide(vec, new Vector2(magnitude));
- }
+ ArrayUtils.insert = function (ary, index, value) {
+ if (!ary)
+ return null;
+ var length = ary.length;
+ if (index > length)
+ index = length;
+ if (index < 0)
+ index = 0;
+ if (index == length)
+ ary.push(value);
+ else if (index == 0)
+ ary.unshift(value);
else {
- vec.x = vec.y = 0;
+ for (var i = length - 1; i >= index; i -= 1) {
+ ary[i + 1] = ary[i];
+ }
+ ary[index] = value;
}
- return vec;
+ return value;
};
- Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) {
- for (var i = 0; i < length; i++) {
- var position = sourceArray[sourceIndex + i];
- var destination = destinationArray[destinationIndex + i];
- destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
- destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
- destinationArray[destinationIndex + i] = destination;
- }
- };
- Vector2Ext.transformR = function (position, matrix) {
- var x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
- var y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
- return new Vector2(x, y);
- };
- Vector2Ext.transform = function (sourceArray, matrix, destinationArray) {
- this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length);
- };
- Vector2Ext.round = function (vec) {
- return new Vector2(Math.round(vec.x), Math.round(vec.y));
- };
- return Vector2Ext;
+ return ArrayUtils;
}());
+var Base64Utils = (function () {
+ function Base64Utils() {
+ }
+ Base64Utils.decode = function (input, isNotStr) {
+ if (isNotStr === void 0) { isNotStr = true; }
+ var output = "";
+ var chr1, chr2, chr3;
+ var enc1, enc2, enc3, enc4;
+ var i = 0;
+ input = this.getConfKey(input);
+ input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
+ while (i < input.length) {
+ enc1 = this._keyAll.indexOf(input.charAt(i++));
+ enc2 = this._keyAll.indexOf(input.charAt(i++));
+ enc3 = this._keyAll.indexOf(input.charAt(i++));
+ enc4 = this._keyAll.indexOf(input.charAt(i++));
+ chr1 = (enc1 << 2) | (enc2 >> 4);
+ chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
+ chr3 = ((enc3 & 3) << 6) | enc4;
+ output = output + String.fromCharCode(chr1);
+ if (enc3 != 64) {
+ if (chr2 == 0) {
+ if (isNotStr)
+ output = output + String.fromCharCode(chr2);
+ }
+ else {
+ output = output + String.fromCharCode(chr2);
+ }
+ }
+ if (enc4 != 64) {
+ if (chr3 == 0) {
+ if (isNotStr)
+ output = output + String.fromCharCode(chr3);
+ }
+ else {
+ output = output + String.fromCharCode(chr3);
+ }
+ }
+ }
+ output = this._utf8_decode(output);
+ return output;
+ };
+ Base64Utils._utf8_encode = function (string) {
+ string = string.replace(/\r\n/g, "\n");
+ var utftext = "";
+ for (var n = 0; n < string.length; n++) {
+ var c = string.charCodeAt(n);
+ if (c < 128) {
+ utftext += String.fromCharCode(c);
+ }
+ else if ((c > 127) && (c < 2048)) {
+ utftext += String.fromCharCode((c >> 6) | 192);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+ else {
+ utftext += String.fromCharCode((c >> 12) | 224);
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+ }
+ return utftext;
+ };
+ Base64Utils._utf8_decode = function (utftext) {
+ var string = "";
+ var i = 0;
+ var c = 0;
+ var c1 = 0;
+ var c2 = 0;
+ var c3 = 0;
+ while (i < utftext.length) {
+ c = utftext.charCodeAt(i);
+ if (c < 128) {
+ string += String.fromCharCode(c);
+ i++;
+ }
+ else if ((c > 191) && (c < 224)) {
+ c2 = utftext.charCodeAt(i + 1);
+ string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
+ i += 2;
+ }
+ else {
+ c2 = utftext.charCodeAt(i + 1);
+ c3 = utftext.charCodeAt(i + 2);
+ string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
+ i += 3;
+ }
+ }
+ return string;
+ };
+ Base64Utils.getConfKey = function (key) {
+ return key.slice(1, key.length);
+ };
+ Base64Utils._keyNum = "0123456789+/";
+ Base64Utils._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ Base64Utils._keyAll = Base64Utils._keyNum + Base64Utils._keyStr;
+ Base64Utils.encode = function (input) {
+ var output = "";
+ var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
+ var i = 0;
+ input = this._utf8_encode(input);
+ while (i < input.length) {
+ chr1 = input.charCodeAt(i++);
+ chr2 = input.charCodeAt(i++);
+ chr3 = input.charCodeAt(i++);
+ enc1 = chr1 >> 2;
+ enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
+ enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
+ enc4 = chr3 & 63;
+ if (isNaN(chr2)) {
+ enc3 = enc4 = 64;
+ }
+ else if (isNaN(chr3)) {
+ enc4 = 64;
+ }
+ output = output +
+ this._keyAll.charAt(enc1) + this._keyAll.charAt(enc2) +
+ this._keyAll.charAt(enc3) + this._keyAll.charAt(enc4);
+ }
+ return this._keyStr.charAt(Math.floor((Math.random() * this._keyStr.length))) + output;
+ };
+ return Base64Utils;
+}());
+var es;
+(function (es) {
+ var ContentManager = (function () {
+ function ContentManager() {
+ this.loadedAssets = new Map();
+ }
+ ContentManager.prototype.loadRes = function (name, local) {
+ var _this = this;
+ if (local === void 0) { local = true; }
+ return new Promise(function (resolve, reject) {
+ var res = _this.loadedAssets.get(name);
+ if (res) {
+ resolve(res);
+ return;
+ }
+ if (local) {
+ RES.getResAsync(name).then(function (data) {
+ _this.loadedAssets.set(name, data);
+ resolve(data);
+ }).catch(function (err) {
+ console.error("资源加载错误:", name, err);
+ reject(err);
+ });
+ }
+ else {
+ RES.getResByUrl(name).then(function (data) {
+ _this.loadedAssets.set(name, data);
+ resolve(data);
+ }).catch(function (err) {
+ console.error("资源加载错误:", name, err);
+ reject(err);
+ });
+ }
+ });
+ };
+ ContentManager.prototype.dispose = function () {
+ this.loadedAssets.forEach(function (value) {
+ var assetsToRemove = value;
+ assetsToRemove.dispose();
+ });
+ this.loadedAssets.clear();
+ };
+ return ContentManager;
+ }());
+ es.ContentManager = ContentManager;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var DrawUtils = (function () {
+ function DrawUtils() {
+ }
+ DrawUtils.drawLine = function (shape, start, end, color, thickness) {
+ if (thickness === void 0) { thickness = 1; }
+ this.drawLineAngle(shape, start, es.MathHelper.angleBetweenVectors(start, end), es.Vector2.distance(start, end), color, thickness);
+ };
+ DrawUtils.drawLineAngle = function (shape, start, radians, length, color, thickness) {
+ if (thickness === void 0) { thickness = 1; }
+ shape.graphics.beginFill(color);
+ shape.graphics.drawRect(start.x, start.y, 1, 1);
+ shape.graphics.endFill();
+ shape.scaleX = length;
+ shape.scaleY = thickness;
+ shape.$anchorOffsetX = 0;
+ shape.$anchorOffsetY = 0;
+ shape.rotation = radians;
+ };
+ DrawUtils.drawHollowRect = function (shape, rect, color, thickness) {
+ if (thickness === void 0) { thickness = 1; }
+ this.drawHollowRectR(shape, rect.x, rect.y, rect.width, rect.height, color, thickness);
+ };
+ DrawUtils.drawHollowRectR = function (shape, x, y, width, height, color, thickness) {
+ if (thickness === void 0) { thickness = 1; }
+ var tl = new es.Vector2(x, y).round();
+ var tr = new es.Vector2(x + width, y).round();
+ var br = new es.Vector2(x + width, y + height).round();
+ var bl = new es.Vector2(x, y + height).round();
+ this.drawLine(shape, tl, tr, color, thickness);
+ this.drawLine(shape, tr, br, color, thickness);
+ this.drawLine(shape, br, bl, color, thickness);
+ this.drawLine(shape, bl, tl, color, thickness);
+ };
+ DrawUtils.drawPixel = function (shape, position, color, size) {
+ if (size === void 0) { size = 1; }
+ var destRect = new es.Rectangle(position.x, position.y, size, size);
+ if (size != 1) {
+ destRect.x -= size * 0.5;
+ destRect.y -= size * 0.5;
+ }
+ shape.graphics.beginFill(color);
+ shape.graphics.drawRect(destRect.x, destRect.y, destRect.width, destRect.height);
+ shape.graphics.endFill();
+ };
+ DrawUtils.getColorMatrix = function (color) {
+ var colorMatrix = [
+ 1, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0,
+ 0, 0, 1, 0, 0,
+ 0, 0, 0, 1, 0
+ ];
+ colorMatrix[0] = Math.floor(color / 256 / 256) / 255;
+ colorMatrix[6] = Math.floor(color / 256 % 256) / 255;
+ colorMatrix[12] = color % 256 / 255;
+ return new egret.ColorMatrixFilter(colorMatrix);
+ };
+ return DrawUtils;
+ }());
+ es.DrawUtils = DrawUtils;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var FuncPack = (function () {
+ function FuncPack(func, context) {
+ this.func = func;
+ this.context = context;
+ }
+ return FuncPack;
+ }());
+ es.FuncPack = FuncPack;
+ var Emitter = (function () {
+ function Emitter() {
+ this._messageTable = new Map();
+ }
+ Emitter.prototype.addObserver = function (eventType, handler, context) {
+ var list = this._messageTable.get(eventType);
+ if (!list) {
+ list = [];
+ this._messageTable.set(eventType, list);
+ }
+ if (list.findIndex(function (funcPack) { return funcPack.func == handler; }) != -1)
+ console.warn("您试图添加相同的观察者两次");
+ list.push(new FuncPack(handler, context));
+ };
+ Emitter.prototype.removeObserver = function (eventType, handler) {
+ var messageData = this._messageTable.get(eventType);
+ var index = messageData.findIndex(function (data) { return data.func == handler; });
+ if (index != -1)
+ messageData.removeAt(index);
+ };
+ Emitter.prototype.emit = function (eventType, data) {
+ var list = this._messageTable.get(eventType);
+ if (list) {
+ for (var i = list.length - 1; i >= 0; i--)
+ list[i].func.call(list[i].context, data);
+ }
+ };
+ return Emitter;
+ }());
+ es.Emitter = Emitter;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var GlobalManager = (function () {
+ function GlobalManager() {
+ }
+ Object.defineProperty(GlobalManager.prototype, "enabled", {
+ get: function () {
+ return this._enabled;
+ },
+ set: function (value) {
+ this.setEnabled(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ GlobalManager.prototype.setEnabled = function (isEnabled) {
+ if (this._enabled != isEnabled) {
+ this._enabled = isEnabled;
+ if (this._enabled) {
+ this.onEnabled();
+ }
+ else {
+ this.onDisabled();
+ }
+ }
+ };
+ GlobalManager.prototype.onEnabled = function () {
+ };
+ GlobalManager.prototype.onDisabled = function () {
+ };
+ GlobalManager.prototype.update = function () {
+ };
+ return GlobalManager;
+ }());
+ es.GlobalManager = GlobalManager;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var TouchState = (function () {
+ function TouchState() {
+ this.x = 0;
+ this.y = 0;
+ this.touchPoint = -1;
+ this.touchDown = false;
+ }
+ Object.defineProperty(TouchState.prototype, "position", {
+ get: function () {
+ return new es.Vector2(this.x, this.y);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ TouchState.prototype.reset = function () {
+ this.x = 0;
+ this.y = 0;
+ this.touchDown = false;
+ this.touchPoint = -1;
+ };
+ return TouchState;
+ }());
+ es.TouchState = TouchState;
+ var Input = (function () {
+ function Input() {
+ }
+ Object.defineProperty(Input, "gameTouchs", {
+ get: function () {
+ return this._gameTouchs;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Input, "resolutionScale", {
+ get: function () {
+ return this._resolutionScale;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Input, "totalTouchCount", {
+ get: function () {
+ return this._totalTouchCount;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Input, "touchPosition", {
+ get: function () {
+ if (!this._gameTouchs[0])
+ return es.Vector2.zero;
+ return this._gameTouchs[0].position;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Input, "maxSupportedTouch", {
+ get: function () {
+ return es.Core._instance.stage.maxTouches;
+ },
+ set: function (value) {
+ es.Core._instance.stage.maxTouches = value;
+ this.initTouchCache();
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Input, "touchPositionDelta", {
+ get: function () {
+ var delta = es.Vector2.subtract(this.touchPosition, this._previousTouchState.position);
+ if (delta.length() > 0) {
+ this.setpreviousTouchState(this._gameTouchs[0]);
+ }
+ return delta;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Input.initialize = function () {
+ if (this._init)
+ return;
+ this._init = true;
+ es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
+ es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this);
+ es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
+ es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this);
+ es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this);
+ this.initTouchCache();
+ };
+ Input.scaledPosition = function (position) {
+ var scaledPos = new es.Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y);
+ return es.Vector2.multiply(scaledPos, this.resolutionScale);
+ };
+ Input.initTouchCache = function () {
+ this._totalTouchCount = 0;
+ this._touchIndex = 0;
+ this._gameTouchs.length = 0;
+ for (var i = 0; i < this.maxSupportedTouch; i++) {
+ this._gameTouchs.push(new TouchState());
+ }
+ };
+ Input.touchBegin = function (evt) {
+ if (this._touchIndex < this.maxSupportedTouch) {
+ this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID;
+ this._gameTouchs[this._touchIndex].touchDown = evt.touchDown;
+ this._gameTouchs[this._touchIndex].x = evt.stageX;
+ this._gameTouchs[this._touchIndex].y = evt.stageY;
+ if (this._touchIndex == 0) {
+ this.setpreviousTouchState(this._gameTouchs[0]);
+ }
+ this._touchIndex++;
+ this._totalTouchCount++;
+ }
+ };
+ Input.touchMove = function (evt) {
+ if (evt.touchPointID == this._gameTouchs[0].touchPoint) {
+ this.setpreviousTouchState(this._gameTouchs[0]);
+ }
+ var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; });
+ if (touchIndex != -1) {
+ var touchData = this._gameTouchs[touchIndex];
+ touchData.x = evt.stageX;
+ touchData.y = evt.stageY;
+ }
+ };
+ Input.touchEnd = function (evt) {
+ var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; });
+ if (touchIndex != -1) {
+ var touchData = this._gameTouchs[touchIndex];
+ touchData.reset();
+ if (touchIndex == 0)
+ this._previousTouchState.reset();
+ this._totalTouchCount--;
+ if (this.totalTouchCount == 0) {
+ this._touchIndex = 0;
+ }
+ }
+ };
+ Input.setpreviousTouchState = function (touchState) {
+ this._previousTouchState = new TouchState();
+ this._previousTouchState.x = touchState.position.x;
+ this._previousTouchState.y = touchState.position.y;
+ this._previousTouchState.touchPoint = touchState.touchPoint;
+ this._previousTouchState.touchDown = touchState.touchDown;
+ };
+ Input._init = false;
+ Input._previousTouchState = new TouchState();
+ Input._resolutionOffset = new es.Vector2();
+ Input._touchIndex = 0;
+ Input._gameTouchs = [];
+ Input._resolutionScale = es.Vector2.one;
+ Input._totalTouchCount = 0;
+ return Input;
+ }());
+ es.Input = Input;
+})(es || (es = {}));
+var KeyboardUtils = (function () {
+ function KeyboardUtils() {
+ }
+ KeyboardUtils.init = function () {
+ this.keyDownDict = {};
+ this.keyUpDict = {};
+ document.addEventListener("keydown", this.onKeyDonwHander);
+ document.addEventListener("keyup", this.onKeyUpHander);
+ };
+ KeyboardUtils.registerKey = function (key, fun, thisObj, type) {
+ if (type === void 0) { type = 0; }
+ var args = [];
+ for (var _i = 4; _i < arguments.length; _i++) {
+ args[_i - 4] = arguments[_i];
+ }
+ var keyDict = type ? this.keyUpDict : this.keyDownDict;
+ keyDict[key] = { "fun": fun, args: args, "thisObj": thisObj };
+ };
+ KeyboardUtils.unregisterKey = function (key, type) {
+ if (type === void 0) { type = 0; }
+ var keyDict = type ? this.keyUpDict : this.keyDownDict;
+ delete keyDict[key];
+ };
+ KeyboardUtils.destroy = function () {
+ this.keyDownDict = null;
+ this.keyUpDict = null;
+ document.removeEventListener("keydown", this.onKeyDonwHander);
+ document.removeEventListener("keyup", this.onKeyUpHander);
+ };
+ KeyboardUtils.onKeyDonwHander = function (event) {
+ if (!this.keyDownDict)
+ return;
+ var key = this.keyCodeToString(event.keyCode);
+ var o = this.keyDownDict[key];
+ if (o) {
+ var fun = o["fun"];
+ var thisObj = o["thisObj"];
+ var args = o["args"];
+ fun.apply(thisObj, args);
+ }
+ };
+ KeyboardUtils.onKeyUpHander = function (event) {
+ if (!this.keyUpDict)
+ return;
+ var key = this.keyCodeToString(event.keyCode);
+ var o = this.keyUpDict[key];
+ if (o) {
+ var fun = o["fun"];
+ var thisObj = o["thisObj"];
+ var args = o["args"];
+ fun.apply(thisObj, args);
+ }
+ };
+ KeyboardUtils.keyCodeToString = function (keyCode) {
+ switch (keyCode) {
+ case 8:
+ return this.BACK_SPACE;
+ case 9:
+ return this.TAB;
+ case 13:
+ return this.ENTER;
+ case 16:
+ return this.SHIFT;
+ case 17:
+ return this.CTRL;
+ case 19:
+ return this.PAUSE_BREAK;
+ case 20:
+ return this.CAPS_LOCK;
+ case 27:
+ return this.ESC;
+ case 32:
+ return this.SPACE;
+ case 33:
+ return this.PAGE_UP;
+ case 34:
+ return this.PAGE_DOWN;
+ case 35:
+ return this.END;
+ case 36:
+ return this.HOME;
+ case 37:
+ return this.LEFT;
+ case 38:
+ return this.UP;
+ case 39:
+ return this.RIGHT;
+ case 40:
+ return this.DOWN;
+ case 45:
+ return this.INSERT;
+ case 46:
+ return this.DELETE;
+ case 91:
+ return this.WINDOWS;
+ case 112:
+ return this.F1;
+ case 113:
+ return this.F2;
+ case 114:
+ return this.F3;
+ case 115:
+ return this.F4;
+ case 116:
+ return this.F5;
+ case 117:
+ return this.F6;
+ case 118:
+ return this.F7;
+ case 119:
+ return this.F8;
+ case 120:
+ return this.F9;
+ case 122:
+ return this.F11;
+ case 123:
+ return this.F12;
+ case 144:
+ return this.NUM_LOCK;
+ case 145:
+ return this.SCROLL_LOCK;
+ default:
+ return String.fromCharCode(keyCode);
+ }
+ };
+ KeyboardUtils.TYPE_KEY_DOWN = 0;
+ KeyboardUtils.TYPE_KEY_UP = 1;
+ KeyboardUtils.A = "A";
+ KeyboardUtils.B = "B";
+ KeyboardUtils.C = "C";
+ KeyboardUtils.D = "D";
+ KeyboardUtils.E = "E";
+ KeyboardUtils.F = "F";
+ KeyboardUtils.G = "G";
+ KeyboardUtils.H = "H";
+ KeyboardUtils.I = "I";
+ KeyboardUtils.J = "J";
+ KeyboardUtils.K = "K";
+ KeyboardUtils.L = "L";
+ KeyboardUtils.M = "M";
+ KeyboardUtils.N = "N";
+ KeyboardUtils.O = "O";
+ KeyboardUtils.P = "P";
+ KeyboardUtils.Q = "Q";
+ KeyboardUtils.R = "R";
+ KeyboardUtils.S = "S";
+ KeyboardUtils.T = "T";
+ KeyboardUtils.U = "U";
+ KeyboardUtils.V = "V";
+ KeyboardUtils.W = "W";
+ KeyboardUtils.X = "X";
+ KeyboardUtils.Y = "Y";
+ KeyboardUtils.Z = "Z";
+ KeyboardUtils.ESC = "Esc";
+ KeyboardUtils.F1 = "F1";
+ KeyboardUtils.F2 = "F2";
+ KeyboardUtils.F3 = "F3";
+ KeyboardUtils.F4 = "F4";
+ KeyboardUtils.F5 = "F5";
+ KeyboardUtils.F6 = "F6";
+ KeyboardUtils.F7 = "F7";
+ KeyboardUtils.F8 = "F8";
+ KeyboardUtils.F9 = "F9";
+ KeyboardUtils.F10 = "F10";
+ KeyboardUtils.F11 = "F11";
+ KeyboardUtils.F12 = "F12";
+ KeyboardUtils.NUM_1 = "1";
+ KeyboardUtils.NUM_2 = "2";
+ KeyboardUtils.NUM_3 = "3";
+ KeyboardUtils.NUM_4 = "4";
+ KeyboardUtils.NUM_5 = "5";
+ KeyboardUtils.NUM_6 = "6";
+ KeyboardUtils.NUM_7 = "7";
+ KeyboardUtils.NUM_8 = "8";
+ KeyboardUtils.NUM_9 = "9";
+ KeyboardUtils.NUM_0 = "0";
+ KeyboardUtils.TAB = "Tab";
+ KeyboardUtils.CTRL = "Ctrl";
+ KeyboardUtils.ALT = "Alt";
+ KeyboardUtils.SHIFT = "Shift";
+ KeyboardUtils.CAPS_LOCK = "Caps Lock";
+ KeyboardUtils.ENTER = "Enter";
+ KeyboardUtils.SPACE = "Space";
+ KeyboardUtils.BACK_SPACE = "Back Space";
+ KeyboardUtils.INSERT = "Insert";
+ KeyboardUtils.DELETE = "Page Down";
+ KeyboardUtils.HOME = "Home";
+ KeyboardUtils.END = "Page Down";
+ KeyboardUtils.PAGE_UP = "Page Up";
+ KeyboardUtils.PAGE_DOWN = "Page Down";
+ KeyboardUtils.LEFT = "Left";
+ KeyboardUtils.RIGHT = "Right";
+ KeyboardUtils.UP = "Up";
+ KeyboardUtils.DOWN = "Down";
+ KeyboardUtils.PAUSE_BREAK = "Pause Break";
+ KeyboardUtils.NUM_LOCK = "Num Lock";
+ KeyboardUtils.SCROLL_LOCK = "Scroll Lock";
+ KeyboardUtils.WINDOWS = "Windows";
+ return KeyboardUtils;
+}());
+var es;
+(function (es) {
+ var ListPool = (function () {
+ function ListPool() {
+ }
+ ListPool.warmCache = function (cacheCount) {
+ cacheCount -= this._objectQueue.length;
+ if (cacheCount > 0) {
+ for (var i = 0; i < cacheCount; i++) {
+ this._objectQueue.unshift([]);
+ }
+ }
+ };
+ ListPool.trimCache = function (cacheCount) {
+ while (cacheCount > this._objectQueue.length)
+ this._objectQueue.shift();
+ };
+ ListPool.clearCache = function () {
+ this._objectQueue.length = 0;
+ };
+ ListPool.obtain = function () {
+ if (this._objectQueue.length > 0)
+ return this._objectQueue.shift();
+ return [];
+ };
+ ListPool.free = function (obj) {
+ this._objectQueue.unshift(obj);
+ obj.length = 0;
+ };
+ ListPool._objectQueue = [];
+ return ListPool;
+ }());
+ es.ListPool = ListPool;
+})(es || (es = {}));
+var THREAD_ID = Math.floor(Math.random() * 1000) + "-" + Date.now();
+var nextTick = function (fn) {
+ setTimeout(fn, 0);
+};
+var LockUtils = (function () {
+ function LockUtils(key) {
+ this._keyX = "mutex_key_" + key + "_X";
+ this._keyY = "mutex_key_" + key + "_Y";
+ this.setItem = egret.localStorage.setItem.bind(localStorage);
+ this.getItem = egret.localStorage.getItem.bind(localStorage);
+ this.removeItem = egret.localStorage.removeItem.bind(localStorage);
+ }
+ LockUtils.prototype.lock = function () {
+ var _this = this;
+ return new Promise(function (resolve, reject) {
+ var fn = function () {
+ _this.setItem(_this._keyX, THREAD_ID);
+ if (!_this.getItem(_this._keyY) === null) {
+ nextTick(fn);
+ }
+ _this.setItem(_this._keyY, THREAD_ID);
+ if (_this.getItem(_this._keyX) !== THREAD_ID) {
+ setTimeout(function () {
+ if (_this.getItem(_this._keyY) !== THREAD_ID) {
+ nextTick(fn);
+ return;
+ }
+ resolve();
+ _this.removeItem(_this._keyY);
+ }, 10);
+ }
+ else {
+ resolve();
+ _this.removeItem(_this._keyY);
+ }
+ };
+ fn();
+ });
+ };
+ return LockUtils;
+}());
+var es;
+(function (es) {
+ var Pair = (function () {
+ function Pair(first, second) {
+ this.first = first;
+ this.second = second;
+ }
+ Pair.prototype.clear = function () {
+ this.first = this.second = null;
+ };
+ Pair.prototype.equals = function (other) {
+ return this.first == other.first && this.second == other.second;
+ };
+ return Pair;
+ }());
+ es.Pair = Pair;
+})(es || (es = {}));
+var RandomUtils = (function () {
+ function RandomUtils() {
+ }
+ RandomUtils.randrange = function (start, stop, step) {
+ if (step === void 0) { step = 1; }
+ if (step == 0)
+ throw new Error('step 不能为 0');
+ var width = stop - start;
+ if (width == 0)
+ throw new Error('没有可用的范围(' + start + ',' + stop + ')');
+ if (width < 0)
+ width = start - stop;
+ var n = Math.floor((width + step - 1) / step);
+ return Math.floor(this.random() * n) * step + Math.min(start, stop);
+ };
+ RandomUtils.randint = function (a, b) {
+ a = Math.floor(a);
+ b = Math.floor(b);
+ if (a > b)
+ a++;
+ else
+ b++;
+ return this.randrange(a, b);
+ };
+ RandomUtils.randnum = function (a, b) {
+ return this.random() * (b - a) + a;
+ };
+ RandomUtils.shuffle = function (array) {
+ array.sort(this._randomCompare);
+ return array;
+ };
+ RandomUtils.choice = function (sequence) {
+ if (!sequence.hasOwnProperty("length"))
+ throw new Error('无法对此对象执行此操作');
+ var index = Math.floor(this.random() * sequence.length);
+ if (sequence instanceof String)
+ return String(sequence).charAt(index);
+ else
+ return sequence[index];
+ };
+ RandomUtils.sample = function (sequence, num) {
+ var len = sequence.length;
+ if (num <= 0 || len < num)
+ throw new Error("采样数量不够");
+ var selected = [];
+ var indices = [];
+ for (var i = 0; i < num; i++) {
+ var index = Math.floor(this.random() * len);
+ while (indices.indexOf(index) >= 0)
+ index = Math.floor(this.random() * len);
+ selected.push(sequence[index]);
+ indices.push(index);
+ }
+ return selected;
+ };
+ RandomUtils.random = function () {
+ return Math.random();
+ };
+ RandomUtils.boolean = function (chance) {
+ if (chance === void 0) { chance = .5; }
+ return (this.random() < chance) ? true : false;
+ };
+ RandomUtils._randomCompare = function (a, b) {
+ return (this.random() > .5) ? 1 : -1;
+ };
+ return RandomUtils;
+}());
+var es;
+(function (es) {
+ var RectangleExt = (function () {
+ function RectangleExt() {
+ }
+ RectangleExt.union = function (first, point) {
+ var rect = new es.Rectangle(point.x, point.y, 0, 0);
+ var result = new es.Rectangle();
+ result.x = Math.min(first.x, rect.x);
+ result.y = Math.min(first.y, rect.y);
+ result.width = Math.max(first.right, rect.right) - result.x;
+ result.height = Math.max(first.bottom, result.bottom) - result.y;
+ return result;
+ };
+ return RectangleExt;
+ }());
+ es.RectangleExt = RectangleExt;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Triangulator = (function () {
+ function Triangulator() {
+ this.triangleIndices = [];
+ this._triPrev = new Array(12);
+ this._triNext = new Array(12);
+ }
+ Triangulator.testPointTriangle = function (point, a, b, c) {
+ if (es.Vector2Ext.cross(es.Vector2.subtract(point, a), es.Vector2.subtract(b, a)) < 0)
+ return false;
+ if (es.Vector2Ext.cross(es.Vector2.subtract(point, b), es.Vector2.subtract(c, b)) < 0)
+ return false;
+ if (es.Vector2Ext.cross(es.Vector2.subtract(point, c), es.Vector2.subtract(a, c)) < 0)
+ return false;
+ return true;
+ };
+ Triangulator.prototype.triangulate = function (points, arePointsCCW) {
+ if (arePointsCCW === void 0) { arePointsCCW = true; }
+ var count = points.length;
+ this.initialize(count);
+ var iterations = 0;
+ var index = 0;
+ while (count > 3 && iterations < 500) {
+ iterations++;
+ var isEar = true;
+ var a = points[this._triPrev[index]];
+ var b = points[index];
+ var c = points[this._triNext[index]];
+ if (es.Vector2Ext.isTriangleCCW(a, b, c)) {
+ var k = this._triNext[this._triNext[index]];
+ do {
+ if (Triangulator.testPointTriangle(points[k], a, b, c)) {
+ isEar = false;
+ break;
+ }
+ k = this._triNext[k];
+ } while (k != this._triPrev[index]);
+ }
+ else {
+ isEar = false;
+ }
+ if (isEar) {
+ this.triangleIndices.push(this._triPrev[index]);
+ this.triangleIndices.push(index);
+ this.triangleIndices.push(this._triNext[index]);
+ this._triNext[this._triPrev[index]] = this._triNext[index];
+ this._triPrev[this._triNext[index]] = this._triPrev[index];
+ count--;
+ index = this._triPrev[index];
+ }
+ else {
+ index = this._triNext[index];
+ }
+ }
+ this.triangleIndices.push(this._triPrev[index]);
+ this.triangleIndices.push(index);
+ this.triangleIndices.push(this._triNext[index]);
+ if (!arePointsCCW)
+ this.triangleIndices.reverse();
+ };
+ Triangulator.prototype.initialize = function (count) {
+ this.triangleIndices.length = 0;
+ if (this._triNext.length < count) {
+ this._triNext.reverse();
+ this._triNext = new Array(Math.max(this._triNext.length * 2, count));
+ }
+ if (this._triPrev.length < count) {
+ this._triPrev.reverse();
+ this._triPrev = new Array(Math.max(this._triPrev.length * 2, count));
+ }
+ for (var i = 0; i < count; i++) {
+ this._triPrev[i] = i - 1;
+ this._triNext[i] = i + 1;
+ }
+ this._triPrev[0] = count - 1;
+ this._triNext[count - 1] = 0;
+ };
+ return Triangulator;
+ }());
+ es.Triangulator = Triangulator;
+})(es || (es = {}));
+var es;
+(function (es) {
+ var Vector2Ext = (function () {
+ function Vector2Ext() {
+ }
+ Vector2Ext.isTriangleCCW = function (a, center, c) {
+ return this.cross(es.Vector2.subtract(center, a), es.Vector2.subtract(c, center)) < 0;
+ };
+ Vector2Ext.cross = function (u, v) {
+ return u.y * v.x - u.x * v.y;
+ };
+ Vector2Ext.perpendicular = function (first, second) {
+ return new es.Vector2(-1 * (second.y - first.y), second.x - first.x);
+ };
+ Vector2Ext.normalize = function (vec) {
+ var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y));
+ if (magnitude > es.MathHelper.Epsilon) {
+ vec = es.Vector2.divide(vec, new es.Vector2(magnitude));
+ }
+ else {
+ vec.x = vec.y = 0;
+ }
+ return vec;
+ };
+ Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) {
+ for (var i = 0; i < length; i++) {
+ var position = sourceArray[sourceIndex + i];
+ var destination = destinationArray[destinationIndex + i];
+ destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
+ destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
+ destinationArray[destinationIndex + i] = destination;
+ }
+ };
+ Vector2Ext.transformR = function (position, matrix) {
+ var x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
+ var y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
+ return new es.Vector2(x, y);
+ };
+ Vector2Ext.transform = function (sourceArray, matrix, destinationArray) {
+ this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length);
+ };
+ Vector2Ext.round = function (vec) {
+ return new es.Vector2(Math.round(vec.x), Math.round(vec.y));
+ };
+ return Vector2Ext;
+ }());
+ es.Vector2Ext = Vector2Ext;
+})(es || (es = {}));
+var WebGLUtils = (function () {
+ function WebGLUtils() {
+ }
+ WebGLUtils.getContext = function () {
+ var canvas = document.getElementsByTagName('canvas')[0];
+ return canvas.getContext('2d');
+ };
+ return WebGLUtils;
+}());
+var es;
+(function (es) {
+ var Layout = (function () {
+ function Layout() {
+ this.clientArea = new es.Rectangle(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height);
+ this.safeArea = this.clientArea;
+ }
+ Layout.prototype.place = function (size, horizontalMargin, verticalMargine, alignment) {
+ var rc = new es.Rectangle(0, 0, size.x, size.y);
+ if ((alignment & Alignment.left) != 0) {
+ rc.x = this.clientArea.x + (this.clientArea.width * horizontalMargin);
+ }
+ else if ((alignment & Alignment.right) != 0) {
+ rc.x = this.clientArea.x + (this.clientArea.width * (1 - horizontalMargin)) - rc.width;
+ }
+ else if ((alignment & Alignment.horizontalCenter) != 0) {
+ rc.x = this.clientArea.x + (this.clientArea.width - rc.width) / 2 + (horizontalMargin * this.clientArea.width);
+ }
+ else {
+ }
+ if ((alignment & Alignment.top) != 0) {
+ rc.y = this.clientArea.y + (this.clientArea.height * verticalMargine);
+ }
+ else if ((alignment & Alignment.bottom) != 0) {
+ rc.y = this.clientArea.y + (this.clientArea.height * (1 - verticalMargine)) - rc.height;
+ }
+ else if ((alignment & Alignment.verticalCenter) != 0) {
+ rc.y = this.clientArea.y + (this.clientArea.height - rc.height) / 2 + (verticalMargine * this.clientArea.height);
+ }
+ else {
+ }
+ if (rc.left < this.safeArea.left)
+ rc.x = this.safeArea.left;
+ if (rc.right > this.safeArea.right)
+ rc.x = this.safeArea.right - rc.width;
+ if (rc.top < this.safeArea.top)
+ rc.y = this.safeArea.top;
+ if (rc.bottom > this.safeArea.bottom)
+ rc.y = this.safeArea.bottom - rc.height;
+ return rc;
+ };
+ return Layout;
+ }());
+ es.Layout = Layout;
+ var Alignment;
+ (function (Alignment) {
+ Alignment[Alignment["none"] = 0] = "none";
+ Alignment[Alignment["left"] = 1] = "left";
+ Alignment[Alignment["right"] = 2] = "right";
+ Alignment[Alignment["horizontalCenter"] = 4] = "horizontalCenter";
+ Alignment[Alignment["top"] = 8] = "top";
+ Alignment[Alignment["bottom"] = 16] = "bottom";
+ Alignment[Alignment["verticalCenter"] = 32] = "verticalCenter";
+ Alignment[Alignment["topLeft"] = 9] = "topLeft";
+ Alignment[Alignment["topRight"] = 10] = "topRight";
+ Alignment[Alignment["topCenter"] = 12] = "topCenter";
+ Alignment[Alignment["bottomLeft"] = 17] = "bottomLeft";
+ Alignment[Alignment["bottomRight"] = 18] = "bottomRight";
+ Alignment[Alignment["bottomCenter"] = 20] = "bottomCenter";
+ Alignment[Alignment["centerLeft"] = 33] = "centerLeft";
+ Alignment[Alignment["centerRight"] = 34] = "centerRight";
+ Alignment[Alignment["center"] = 36] = "center";
+ })(Alignment = es.Alignment || (es.Alignment = {}));
+})(es || (es = {}));
+var stopwatch;
+(function (stopwatch) {
+ var Stopwatch = (function () {
+ function Stopwatch(getSystemTime) {
+ if (getSystemTime === void 0) { getSystemTime = _defaultSystemTimeGetter; }
+ this.getSystemTime = getSystemTime;
+ this._stopDuration = 0;
+ this._completeSlices = [];
+ }
+ Stopwatch.prototype.getState = function () {
+ if (this._startSystemTime === undefined) {
+ return State.IDLE;
+ }
+ else if (this._stopSystemTime === undefined) {
+ return State.RUNNING;
+ }
+ else {
+ return State.STOPPED;
+ }
+ };
+ Stopwatch.prototype.isIdle = function () {
+ return this.getState() === State.IDLE;
+ };
+ Stopwatch.prototype.isRunning = function () {
+ return this.getState() === State.RUNNING;
+ };
+ Stopwatch.prototype.isStopped = function () {
+ return this.getState() === State.STOPPED;
+ };
+ Stopwatch.prototype.slice = function () {
+ return this.recordPendingSlice();
+ };
+ Stopwatch.prototype.getCompletedSlices = function () {
+ return Array.from(this._completeSlices);
+ };
+ Stopwatch.prototype.getCompletedAndPendingSlices = function () {
+ return this._completeSlices.concat([this.getPendingSlice()]);
+ };
+ Stopwatch.prototype.getPendingSlice = function () {
+ return this.calculatePendingSlice();
+ };
+ Stopwatch.prototype.getTime = function () {
+ return this.caculateStopwatchTime();
+ };
+ Stopwatch.prototype.reset = function () {
+ this._startSystemTime = this._pendingSliceStartStopwatchTime = this._stopSystemTime = undefined;
+ this._stopDuration = 0;
+ this._completeSlices = [];
+ };
+ Stopwatch.prototype.start = function (forceReset) {
+ if (forceReset === void 0) { forceReset = false; }
+ if (forceReset) {
+ this.reset();
+ }
+ if (this._stopSystemTime !== undefined) {
+ var systemNow = this.getSystemTime();
+ var stopDuration = systemNow - this._stopSystemTime;
+ this._stopDuration += stopDuration;
+ this._stopSystemTime = undefined;
+ }
+ else if (this._startSystemTime === undefined) {
+ var systemNow = this.getSystemTime();
+ this._startSystemTime = systemNow;
+ this._pendingSliceStartStopwatchTime = 0;
+ }
+ };
+ Stopwatch.prototype.stop = function (recordPendingSlice) {
+ if (recordPendingSlice === void 0) { recordPendingSlice = false; }
+ if (this._startSystemTime === undefined) {
+ return 0;
+ }
+ var systemTimeOfStopwatchTime = this.getSystemTimeOfCurrentStopwatchTime();
+ if (recordPendingSlice) {
+ this.recordPendingSlice(this.caculateStopwatchTime(systemTimeOfStopwatchTime));
+ }
+ this._stopSystemTime = systemTimeOfStopwatchTime;
+ return this.getTime();
+ };
+ Stopwatch.prototype.calculatePendingSlice = function (endStopwatchTime) {
+ if (this._pendingSliceStartStopwatchTime === undefined) {
+ return Object.freeze({ startTime: 0, endTime: 0, duration: 0 });
+ }
+ if (endStopwatchTime === undefined) {
+ endStopwatchTime = this.getTime();
+ }
+ return Object.freeze({
+ startTime: this._pendingSliceStartStopwatchTime,
+ endTime: endStopwatchTime,
+ duration: endStopwatchTime - this._pendingSliceStartStopwatchTime
+ });
+ };
+ Stopwatch.prototype.caculateStopwatchTime = function (endSystemTime) {
+ if (this._startSystemTime === undefined)
+ return 0;
+ if (endSystemTime === undefined)
+ endSystemTime = this.getSystemTimeOfCurrentStopwatchTime();
+ return endSystemTime - this._startSystemTime - this._stopDuration;
+ };
+ Stopwatch.prototype.getSystemTimeOfCurrentStopwatchTime = function () {
+ return this._stopSystemTime === undefined ? this.getSystemTime() : this._stopSystemTime;
+ };
+ Stopwatch.prototype.recordPendingSlice = function (endStopwatchTime) {
+ if (this._pendingSliceStartStopwatchTime !== undefined) {
+ if (endStopwatchTime === undefined) {
+ endStopwatchTime = this.getTime();
+ }
+ var slice = this.calculatePendingSlice(endStopwatchTime);
+ this._pendingSliceStartStopwatchTime = slice.endTime;
+ this._completeSlices.push(slice);
+ return slice;
+ }
+ else {
+ return this.calculatePendingSlice();
+ }
+ };
+ return Stopwatch;
+ }());
+ stopwatch.Stopwatch = Stopwatch;
+ var State;
+ (function (State) {
+ State["IDLE"] = "IDLE";
+ State["RUNNING"] = "RUNNING";
+ State["STOPPED"] = "STOPPED";
+ })(State || (State = {}));
+ function setDefaultSystemTimeGetter(systemTimeGetter) {
+ if (systemTimeGetter === void 0) { systemTimeGetter = Date.now; }
+ _defaultSystemTimeGetter = systemTimeGetter;
+ }
+ stopwatch.setDefaultSystemTimeGetter = setDefaultSystemTimeGetter;
+ var _defaultSystemTimeGetter = Date.now;
+})(stopwatch || (stopwatch = {}));
+var es;
+(function (es) {
+ var TimeRuler = (function () {
+ function TimeRuler() {
+ this.showLog = false;
+ this._frameKey = 'frame';
+ this._logKey = 'log';
+ this.markers = [];
+ this.stopwacth = new stopwatch.Stopwatch();
+ this._markerNameToIdMap = new Map();
+ this._logs = new Array(2);
+ for (var i = 0; i < this._logs.length; ++i)
+ this._logs[i] = new FrameLog();
+ this.sampleFrames = this.targetSampleFrames = 1;
+ this.width = es.Core.graphicsDevice.viewport.width * 0.8;
+ es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this);
+ this.onGraphicsDeviceReset();
+ }
+ Object.defineProperty(TimeRuler, "Instance", {
+ get: function () {
+ if (!this._instance)
+ this._instance = new TimeRuler();
+ return this._instance;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ TimeRuler.prototype.startFrame = function () {
+ var _this = this;
+ var lock = new LockUtils(this._frameKey);
+ lock.lock().then(function () {
+ _this._updateCount = parseInt(egret.localStorage.getItem(_this._frameKey), 10);
+ if (isNaN(_this._updateCount))
+ _this._updateCount = 0;
+ var count = _this._updateCount;
+ count += 1;
+ egret.localStorage.setItem(_this._frameKey, count.toString());
+ if (_this.enabled && (1 < count && count < TimeRuler.maxSampleFrames))
+ return;
+ _this._prevLog = _this._logs[_this.frameCount++ & 0x1];
+ _this._curLog = _this._logs[_this.frameCount & 0x1];
+ var endFrameTime = _this.stopwacth.getTime();
+ for (var barIndex = 0; barIndex < _this._prevLog.bars.length; ++barIndex) {
+ var prevBar = _this._prevLog.bars[barIndex];
+ var nextBar = _this._curLog.bars[barIndex];
+ for (var nest = 0; nest < prevBar.nestCount; ++nest) {
+ var markerIdx = prevBar.markerNests[nest];
+ prevBar.markers[markerIdx].endTime = endFrameTime;
+ nextBar.markerNests[nest] = nest;
+ nextBar.markers[nest].markerId = prevBar.markers[markerIdx].markerId;
+ nextBar.markers[nest].beginTime = 0;
+ nextBar.markers[nest].endTime = -1;
+ nextBar.markers[nest].color = prevBar.markers[markerIdx].color;
+ }
+ for (var markerIdx = 0; markerIdx < prevBar.markCount; ++markerIdx) {
+ var duration = prevBar.markers[markerIdx].endTime - prevBar.markers[markerIdx].beginTime;
+ var markerId = prevBar.markers[markerIdx].markerId;
+ var m = _this.markers[markerId];
+ m.logs[barIndex].color = prevBar.markers[markerIdx].color;
+ if (!m.logs[barIndex].initialized) {
+ m.logs[barIndex].min = duration;
+ m.logs[barIndex].max = duration;
+ m.logs[barIndex].avg = duration;
+ m.logs[barIndex].initialized = true;
+ }
+ else {
+ m.logs[barIndex].min = Math.min(m.logs[barIndex].min, duration);
+ m.logs[barIndex].max = Math.min(m.logs[barIndex].max, duration);
+ m.logs[barIndex].avg += duration;
+ m.logs[barIndex].avg *= 0.5;
+ if (m.logs[barIndex].samples++ >= TimeRuler.logSnapDuration) {
+ m.logs[barIndex].snapMin = m.logs[barIndex].min;
+ m.logs[barIndex].snapMax = m.logs[barIndex].max;
+ m.logs[barIndex].snapAvg = m.logs[barIndex].avg;
+ m.logs[barIndex].samples = 0;
+ }
+ }
+ }
+ nextBar.markCount = prevBar.nestCount;
+ nextBar.nestCount = prevBar.nestCount;
+ }
+ _this.stopwacth.reset();
+ _this.stopwacth.start();
+ });
+ };
+ TimeRuler.prototype.beginMark = function (markerName, color, barIndex) {
+ var _this = this;
+ if (barIndex === void 0) { barIndex = 0; }
+ var lock = new LockUtils(this._frameKey);
+ lock.lock().then(function () {
+ if (barIndex < 0 || barIndex >= TimeRuler.maxBars)
+ throw new Error("barIndex argument out of range");
+ var bar = _this._curLog.bars[barIndex];
+ if (bar.markCount >= TimeRuler.maxSamples) {
+ throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");
+ }
+ if (bar.nestCount >= TimeRuler.maxNestCall) {
+ throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");
+ }
+ var markerId = _this._markerNameToIdMap.get(markerName);
+ if (isNaN(markerId)) {
+ markerId = _this.markers.length;
+ _this._markerNameToIdMap.set(markerName, markerId);
+ }
+ bar.markerNests[bar.nestCount++] = bar.markCount;
+ bar.markers[bar.markCount].markerId = markerId;
+ bar.markers[bar.markCount].color = color;
+ bar.markers[bar.markCount].beginTime = _this.stopwacth.getTime();
+ bar.markers[bar.markCount].endTime = -1;
+ });
+ };
+ TimeRuler.prototype.endMark = function (markerName, barIndex) {
+ var _this = this;
+ if (barIndex === void 0) { barIndex = 0; }
+ var lock = new LockUtils(this._frameKey);
+ lock.lock().then(function () {
+ if (barIndex < 0 || barIndex >= TimeRuler.maxBars)
+ throw new Error("barIndex argument out of range");
+ var bar = _this._curLog.bars[barIndex];
+ if (bar.nestCount <= 0) {
+ throw new Error("call beginMark method before calling endMark method");
+ }
+ var markerId = _this._markerNameToIdMap.get(markerName);
+ if (isNaN(markerId)) {
+ throw new Error("Marker " + markerName + " is not registered. Make sure you specifed same name as you used for beginMark method");
+ }
+ var markerIdx = bar.markerNests[--bar.nestCount];
+ if (bar.markers[markerIdx].markerId != markerId) {
+ throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");
+ }
+ bar.markers[markerIdx].endTime = _this.stopwacth.getTime();
+ });
+ };
+ TimeRuler.prototype.getAverageTime = function (barIndex, markerName) {
+ if (barIndex < 0 || barIndex >= TimeRuler.maxBars) {
+ throw new Error("barIndex argument out of range");
+ }
+ var result = 0;
+ var markerId = this._markerNameToIdMap.get(markerName);
+ if (markerId) {
+ result = this.markers[markerId].logs[barIndex].avg;
+ }
+ return result;
+ };
+ TimeRuler.prototype.resetLog = function () {
+ var _this = this;
+ var lock = new LockUtils(this._logKey);
+ lock.lock().then(function () {
+ var count = parseInt(egret.localStorage.getItem(_this._logKey), 10);
+ count += 1;
+ egret.localStorage.setItem(_this._logKey, count.toString());
+ _this.markers.forEach(function (markerInfo) {
+ for (var i = 0; i < markerInfo.logs.length; ++i) {
+ markerInfo.logs[i].initialized = false;
+ markerInfo.logs[i].snapMin = 0;
+ markerInfo.logs[i].snapMax = 0;
+ markerInfo.logs[i].snapAvg = 0;
+ markerInfo.logs[i].min = 0;
+ markerInfo.logs[i].max = 0;
+ markerInfo.logs[i].avg = 0;
+ markerInfo.logs[i].samples = 0;
+ }
+ });
+ });
+ };
+ TimeRuler.prototype.render = function (position, width) {
+ if (position === void 0) { position = this._position; }
+ if (width === void 0) { width = this.width; }
+ egret.localStorage.setItem(this._frameKey, "0");
+ if (!this.showLog)
+ return;
+ var height = 0;
+ var maxTime = 0;
+ this._prevLog.bars.forEach(function (bar) {
+ if (bar.markCount > 0) {
+ height += TimeRuler.barHeight + TimeRuler.barPadding * 2;
+ maxTime = Math.max(maxTime, bar.markers[bar.markCount - 1].endTime);
+ }
+ });
+ var frameSpan = 1 / 60 * 1000;
+ var sampleSpan = this.sampleFrames * frameSpan;
+ if (maxTime > sampleSpan) {
+ this._frameAdjust = Math.max(0, this._frameAdjust) + 1;
+ }
+ else {
+ this._frameAdjust = Math.min(0, this._frameAdjust) - 1;
+ }
+ if (Math.max(this._frameAdjust) > TimeRuler.autoAdjustDelay) {
+ this.sampleFrames = Math.min(TimeRuler.maxSampleFrames, this.sampleFrames);
+ this.sampleFrames = Math.max(this.targetSampleFrames, (maxTime / frameSpan) + 1);
+ this._frameAdjust = 0;
+ }
+ var msToPs = width / sampleSpan;
+ var startY = position.y - (height - TimeRuler.barHeight);
+ var y = startY;
+ };
+ TimeRuler.prototype.onGraphicsDeviceReset = function () {
+ var layout = new es.Layout();
+ this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location;
+ };
+ TimeRuler.maxBars = 8;
+ TimeRuler.maxSamples = 256;
+ TimeRuler.maxNestCall = 32;
+ TimeRuler.barHeight = 8;
+ TimeRuler.maxSampleFrames = 4;
+ TimeRuler.logSnapDuration = 120;
+ TimeRuler.barPadding = 2;
+ TimeRuler.autoAdjustDelay = 30;
+ return TimeRuler;
+ }());
+ es.TimeRuler = TimeRuler;
+ var FrameLog = (function () {
+ function FrameLog() {
+ this.bars = new Array(TimeRuler.maxBars);
+ this.bars.fill(new MarkerCollection(), 0, TimeRuler.maxBars);
+ }
+ return FrameLog;
+ }());
+ es.FrameLog = FrameLog;
+ var MarkerCollection = (function () {
+ function MarkerCollection() {
+ this.markers = new Array(TimeRuler.maxSamples);
+ this.markCount = 0;
+ this.markerNests = new Array(TimeRuler.maxNestCall);
+ this.nestCount = 0;
+ this.markers.fill(new Marker(), 0, TimeRuler.maxSamples);
+ this.markerNests.fill(0, 0, TimeRuler.maxNestCall);
+ }
+ return MarkerCollection;
+ }());
+ es.MarkerCollection = MarkerCollection;
+ var Marker = (function () {
+ function Marker() {
+ this.markerId = 0;
+ this.beginTime = 0;
+ this.endTime = 0;
+ this.color = 0x000000;
+ }
+ return Marker;
+ }());
+ es.Marker = Marker;
+ var MarkerInfo = (function () {
+ function MarkerInfo(name) {
+ this.logs = new Array(TimeRuler.maxBars);
+ this.name = name;
+ this.logs.fill(new MarkerLog(), 0, TimeRuler.maxBars);
+ }
+ return MarkerInfo;
+ }());
+ es.MarkerInfo = MarkerInfo;
+ var MarkerLog = (function () {
+ function MarkerLog() {
+ this.snapMin = 0;
+ this.snapMax = 0;
+ this.snapAvg = 0;
+ this.min = 0;
+ this.max = 0;
+ this.avg = 0;
+ this.samples = 0;
+ this.color = 0x000000;
+ this.initialized = false;
+ }
+ return MarkerLog;
+ }());
+ es.MarkerLog = MarkerLog;
+})(es || (es = {}));
diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js
index e9723556..e6cf4f42 100644
--- a/demo/libs/framework/framework.min.js
+++ b/demo/libs/framework/framework.min.js
@@ -1 +1 @@
-window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(o,r){function s(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===c())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.update=function(){},e.prototype.debugRender=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer),Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,o=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-o)/2,i,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,o=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*o,this.uvs.width=e.width*i,this.uvs.height=e.height*o}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),e.prototype.setSprite=function(t){return this.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var o=Math.floor(i/e),r=t.sprites.length;if(r>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=r-1;this.currentFrame=s-Math.abs(s-o%(2*s))}else this.currentFrame=o%r;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.Bitmap(this.sprite.texture2D),o=new egret.Rectangle(this.sourceRect.x,this.sourceRect.y,this.sourceRect.width,this.sourceRect.height);n.drawToTexture(i,o),this.bitmap.texture=n}},e}(SpriteRenderer),Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var o=t.toRadians(i);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=o||0,this.m32=r||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,o=e.m11*n.m11+e.m12*n.m21,r=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=o,i.m12=r,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,n,i,o)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*o.y-a.y*o.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return o;var u=(c.x*r.y-c.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(h*r.x,h*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var o=Vector2Ext.perpendicular(i,t);o=Vector2.normalize(o),this._edgeNormals[n]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(o=!1),!o)return null;(g=Math.abs(g))i&&(i=o);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,i),r=o.closestPoint,s=o.distanceSquared;n.normal=o.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(r,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var o=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,o),n}var r=Vector2.distanceSquared(i,t.position);if(0==r)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(i=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,o){var r=n.loadedAssets.get(t);r?i(r):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var n=this._messageTable.get(t);n||(n=[],this._messageTable.set(t,n)),n.contains(e)&&console.warn("您试图添加相同的观察者两次"),n.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var n=new Rectangle(e.x,e.y,0,0);return this.unionR(t,n)},t.unionR=function(t,e){var n=new Rectangle;return n.x=Math.min(t.x,e.x),n.y=Math.min(t.y,e.y),n.width=Math.max(t.right,e.right)-n.x,n.height=Math.max(t.bottom,e.bottom)-n.y,n},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],c=e[r],h=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,o,r){for(var s=0;s0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},t.prototype.enqueue=function(t,e){t.priority=e,this._numNodes++,this._nodes[this._numNodes]=t,t.queueIndex=this._numNodes,t.insertionIndex=this._numNodesEverEnqueued++,this.cascadeUp(this._nodes[this._numNodes])},t.prototype.dequeue=function(){var t=this._nodes[1];return this.remove(t),t},t.prototype.remove=function(t){if(t.queueIndex==this._numNodes)return this._nodes[this._numNodes]=null,void this._numNodes--;var e=this._nodes[this._numNodes];this.swap(t,e),delete this._nodes[this._numNodes],this._numNodes--,this.onNodeUpdated(e)},t.prototype.isValidQueue=function(){for(var t=1;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=null!=e?e:this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);return this.x*=t,this.y*=t,this},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},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.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.updateInterval=1,e._enabled=!0,e._updateOrder=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.debugRender=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.update=function(){},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},e.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},e.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},e}(egret.HashObject);t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n}(egret.DisplayObjectContainer);t.Core=e}(es||(es={})),function(t){!function(t){t[t.GraphicsDeviceReset=0]="GraphicsDeviceReset",t[t.SceneChanged=1]="SceneChanged",t[t.OrientationChanged=2]="OrientationChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localScale",{get:function(){return this.transform.localScale},set:function(t){this.transform.setLocalScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene&&(this.scene.entities.markEntityListUnsorted(),this.scene.entities.markTagUnsorted(this.tag)),this},e.prototype.destroy=function(){this._isDestroyed=!0,this.scene.entities.remove(this),this.transform.parent=null;for(var t=this.transform.childCount-1;t>=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(this._translationMatrix),this.parent||(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),this.parent&&(this._worldTransform=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r.prototype.updateMatrixes=function(){var e;this._areMatrixedDirty&&(this._transformMatrix=t.Matrix2D.create().translate(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(e=t.Matrix2D.create().scale(this._zoom,this._zoom),this._transformMatrix=this._transformMatrix.multiply(e)),0!=this.entity.transform.rotation&&(e=t.Matrix2D.create().rotate(this.entity.transform.rotation),this._transformMatrix=this._transformMatrix.multiply(e)),e=t.Matrix2D.create().translate(this._origin.x,this._origin.y),this._transformMatrix=this._transformMatrix.multiply(e),this._inverseTransformMatrix=this._transformMatrix.invert(),this._areBoundsDirty=!0,this._areMatrixedDirty=!1)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._areBoundsDirty=!0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this._mesh.$renderNode=new egret.sys.RenderNode,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t),this.displayObject.x=this.entity.position.x-this.origin.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y-this.origin.y+this.localOffset.y-t.position.y+t.origin.y},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(e){function n(n){var i=e.call(this,n)||this;return i._sourceRect=new t.Rectangle,i._textureScale=t.Vector2.one,i._inverseTexScale=t.Vector2.one,i._sourceRect=n.sourceRect,i.displayObject.$fillMode=egret.BitmapFillMode.REPEAT,i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scrollX",{get:function(){return this._sourceRect.x},set:function(t){this._sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scrollY",{get:function(){return this._sourceRect.y},set:function(t){this._sourceRect.y=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"textureScale",{get:function(){return this._textureScale},set:function(e){this._textureScale=e,this._inverseTexScale=new t.Vector2(1/this._textureScale.x,1/this._textureScale.y),this._sourceRect.width=this._sprite.sourceRect.width*this._inverseTexScale.x,this._sourceRect.height=this._sprite.sourceRect.height*this._inverseTexScale.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"width",{get:function(){return this._sourceRect.width},set:function(t){this._areBoundsDirty=!0,this._sourceRect.width=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this._sourceRect.height},set:function(t){this._areBoundsDirty=!0,this._sourceRect.height=t},enumerable:!0,configurable:!0}),n.prototype.render=function(t){var n=this.displayObject;n.width=this.width,n.height=this.height,e.prototype.render.call(this,t)},n}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(t){var n=e.call(this,t)||this;return n.scrollSpeedX=15,n.scroolSpeedY=0,n._scrollX=0,n._scrollY=0,n}return __extends(n,e),Object.defineProperty(n.prototype,"textureScale",{get:function(){return this._textureScale},set:function(e){this._textureScale=e,this._inverseTexScale=new t.Vector2(1/this._textureScale.x,1/this._textureScale.y)},enumerable:!0,configurable:!0}),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this._sourceRect.x=this._scrollX,this._sourceRect.y=this._scrollY},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._elapsedTime=0,e._animations=new Map,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.LONG_MASK=63,t}();t.BitSet=e}(es||(es={})),function(t){var e=function(){function e(t){this._components=[],this._componentsToAdd=[],this._componentsToRemove=[],this._tempBufferList=[],this._entity=t}return Object.defineProperty(e.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),e.prototype.markEntityListUnsorted=function(){this._isComponentListUnsorted=!0},e.prototype.add=function(t){this._componentsToAdd.push(t)},e.prototype.remove=function(t){this._componentsToRemove.contains(t)&&console.warn("You are trying to remove a Component ("+t+") that you already removed"),this._componentsToAdd.contains(t)?this._componentsToAdd.remove(t):this._componentsToRemove.push(t)},e.prototype.removeAllComponents=function(){for(var t=0;t0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.fromMinMax=function(t,e,i,r){return new n(t,e,i-t,r-e)},n.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)},n.prototype.intersects=function(t){return t.leftthis.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=Math.max(r,e))>(n=Math.min(o,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,c=(this.y-t.start.y)*a,h=(this.y+this.height-t.start.y)*a;if(c>h){var u=c;c=h,h=u}if((e=Math.max(c,e))>(n=Math.max(h,n)))return e}return e},n.prototype.containsRect=function(t){return this.x<=t.x&&t.x1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){return function(e,n){this.start=e,this.end=n,this.direction=t.Vector2.subtract(this.end,this.start)}}();t.Ray2D=e}(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.setValues=function(t,e,n,i){this.collider=t,this.fraction=e,this.distance=n,this.point=i},e.prototype.setValuesNonCollider=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.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 t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;rr&&(r=s,i=o)}return e[i]},n.getClosestPointOnPolygonToPoint=function(e,n,i,r){i=Number.MAX_VALUE,r=new t.Vector2(0,0);for(var o,s=new t.Vector2(0,0),a=0;ae.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o1)return s;var a,c=t.Vector2.add(o.start,t.Vector2.add(o.direction,new t.Vector2(s))),h=0;c.xn.bounds.right&&(h|=1),c.yn.bounds.bottom&&(h|=2);var u=a+h;return 3==u&&console.log("m == 3. corner "+t.Time.frameCount),s},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(){function e(){}return e.polygonToPolygon=function(e,n,i){for(var r,o=!0,s=e.edgeNormals,a=n.edgeNormals,c=Number.POSITIVE_INFINITY,h=new t.Vector2,u=t.Vector2.subtract(e.position,n.position),l=0;l0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.multiply(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r1)return!1;var l=(h.x*s.y-h.y*s.x)/c;return!(l<0||l>1)&&(o=o.add(e).add(t.Vector2.multiply(new t.Vector2(u),s)),!0)},e.lineToCircle=function(e,n,i,r){var o=t.Vector2.distance(e,n),s=t.Vector2.divide(t.Vector2.subtract(n,e),new t.Vector2(o)),a=t.Vector2.subtract(e,i.position),c=t.Vector2.dot(a,s),h=t.Vector2.dot(a,a)-i.radius*i.radius;if(h>0&&c>0)return!1;var u=c*c-h;return!(u<0)&&(r.fraction=-c-Math.sqrt(u),r.fraction<0&&(r.fraction=0),r.point=t.Vector2.add(e,t.Vector2.multiply(new t.Vector2(r.fraction),s)),r.distance=t.Vector2.distance(e,r.point),r.normal=t.Vector2.normalize(t.Vector2.subtract(r.point,i.position)),r.fraction=r.distance/o,!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),r.normal=r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,new t.Vector2(-i.x)),c=o.rayIntersects(a);return c<=1&&(r.fraction=c,r.distance=i.length()*c,r.normal=new t.Vector2(-i.x),r.normal=r.normal.normalize(),r.centroid=t.Vector2.add(e.bounds.center,t.Vector2.multiply(i,new t.Vector2(c))),!0)},e}();t.ShapeCollisions=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=[],this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds;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++){var a=this.cellAtPosition(o,s,!0);a.firstOrDefault(function(t){return t.hashCode==e.hashCode})||a.push(e)}},e.prototype.remove=function(t){for(var e=t.registeredPhysicsBounds,n=this.cellCoords(e.x,e.y),i=this.cellCoords(e.right,e.bottom),r=n.x;r<=i.x;r++)for(var o=n.y;o<=i.y;o++){var s=this.cellAtPosition(r,o);s?s.remove(t):console.error("removing Collider ["+t+"] from a cell that it is not present in")}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.debugDraw=function(t,e){void 0===e&&(e=1);for(var n=this.gridBounds.x;n<=this.gridBounds.right;n++)for(var i=this.gridBounds.y;i<=this.gridBounds.bottom;i++){var r=this.cellAtPosition(n,i);r&&r.length>0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=function(r){var o=c[r];if(o==n||!t.Flags.isFlagSet(i,o.physicsLayer))return"continue";e.intersects(o.bounds)&&(u._tempHashSet.firstOrDefault(function(t){return t.hashCode==o.hashCode})||u._tempHashSet.push(o))},u=this,l=0;ln;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.scaledPosition=function(e){var n=new t.Vector2(e.x-this._resolutionOffset.x,e.y-this._resolutionOffset.y);return t.Vector2.multiply(n,this.resolutionScale)},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y",this.setItem=egret.localStorage.setItem.bind(localStorage),this.getItem=egret.localStorage.getItem.bind(localStorage),this.removeItem=egret.localStorage.removeItem.bind(localStorage)}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){t.setItem(t._keyX,THREAD_ID),null===!t.getItem(t._keyY)&&nextTick(i),t.setItem(t._keyY,THREAD_ID),t.getItem(t._keyX)!==THREAD_ID?setTimeout(function(){t.getItem(t._keyY)===THREAD_ID?(e(),t.removeItem(t._keyY)):nextTick(i)},10):(e(),t.removeItem(t._keyY))};i()})},t}();!function(t){var e=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t.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}();!function(t){var e=function(){function e(){}return 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,r.bottom)-r.y,r},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){function e(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return e.testPointTriangle=function(e,n,i,r){return!(t.Vector2Ext.cross(t.Vector2.subtract(e,n),t.Vector2.subtract(i,n))<0)&&(!(t.Vector2Ext.cross(t.Vector2.subtract(e,i),t.Vector2.subtract(r,i))<0)&&!(t.Vector2Ext.cross(t.Vector2.subtract(e,r),t.Vector2.subtract(n,r))<0))},e.prototype.triangulate=function(n,i){void 0===i&&(i=!0);var r=n.length;this.initialize(r);for(var o=0,s=0;r>3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.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}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this.showLog=!1,this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.prototype.onGraphicsDeviceReset=function(){var n=new t.Layout;this._position=n.place(new t.Vector2(this.width,e.barHeight),0,.01,t.Alignment.bottomCenter).location},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={}));
\ No newline at end of file
diff --git a/demo/manifest.json b/demo/manifest.json
index 2d454643..522c8eec 100644
--- a/demo/manifest.json
+++ b/demo/manifest.json
@@ -11,12 +11,11 @@
"libs/long/long.js"
],
"game": [
- "bin-debug/game/CoreEmitterType.js",
"bin-debug/AssetAdapter.js",
+ "bin-debug/LoadingUI.js",
"bin-debug/Main.js",
"bin-debug/Platform.js",
"bin-debug/ThemeAdapter.js",
- "bin-debug/LoadingUI.js",
"bin-debug/game/MainScene.js",
"bin-debug/game/PlayerController.js",
"bin-debug/game/SimplePooled.js",
diff --git a/demo/scripts/wxgame/wxgame.ts b/demo/scripts/wxgame/wxgame.ts
index be865602..13943ce1 100644
--- a/demo/scripts/wxgame/wxgame.ts
+++ b/demo/scripts/wxgame/wxgame.ts
@@ -44,6 +44,9 @@ export class WxgamePlugin implements plugins.Command {
if (filename == 'main.js') {
content += "\n;window.Main = Main;"
}
+ if (filename == 'libs/long/long.js' || filename == 'libs/long/long.min.js'){
+ content += "window.Long = long;"
+ }
this.md5Obj[path.basename(filename)] = this.md5(content)
file.contents = new Buffer(content);
}
diff --git a/demo/src/Main.ts b/demo/src/Main.ts
index 2233ec36..0ac8bbb8 100644
--- a/demo/src/Main.ts
+++ b/demo/src/Main.ts
@@ -27,71 +27,29 @@
//
//////////////////////////////////////////////////////////////////////////////////////
-
-class Main extends eui.UILayer {
- public static emitter: Emitter;
- public static manager: SceneManager;
-
- protected createChildren(): void {
- super.createChildren();
-
- egret.lifecycle.addLifecycleListener((context) => {
- // custom lifecycle plugin
- })
-
- egret.lifecycle.onPause = () => {
- egret.ticker.pause();
- }
-
- egret.lifecycle.onResume = () => {
- egret.ticker.resume();
- }
-
- //inject the custom material parser
- //注入自定义的素材解析器
- let assetAdapter = new AssetAdapter();
- egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
- egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
-
- Main.manager = new SceneManager(this.stage);
- Main.emitter = new Emitter();
- this.addEventListener(egret.Event.ENTER_FRAME, this.updateFrame, this);
+class Main extends es.Core {
+ protected initialize() {
this.runGame();
}
- private updateFrame(evt: egret.Event){
- Main.emitter.emit(CoreEmitterType.Update, evt);
+ private runGame() {
+ this.loadResource();
}
- private async runGame() {
- await this.loadResource();
- this.createGameScene();
- }
- private async loadResource() {
- try {
- const loadingView = new LoadingUI();
- this.stage.addChild(loadingView);
- await RES.loadConfig("resource/default.res.json", "resource/");
- await this.loadTheme();
- await RES.loadGroup("preload", 0, loadingView);
- this.stage.removeChild(loadingView);
- }
- catch (e) {
- console.error(e);
- }
- }
-
- private loadTheme() {
- return new Promise((resolve, reject) => {
- // load skin theme configuration file, you can manually modify the file. And replace the default skin.
- //加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
- let theme = new eui.Theme("resource/default.thm.json", this.stage);
- theme.addEventListener(eui.UIEvent.COMPLETE, () => {
- resolve();
- }, this);
-
- })
+ private loadResource() {
+ const loadingView = new LoadingUI();
+ this.stage.addChild(loadingView);
+ RES.loadConfig("resource/default.res.json", "resource/").then(()=>{
+ RES.loadGroup("preload", 0, loadingView).then(()=>{
+ this.stage.removeChild(loadingView);
+ this.createGameScene();
+ }).catch(err => {
+ console.error(err);
+ });
+ }).catch(err =>{
+ console.error(err);
+ });
}
/**
@@ -99,10 +57,6 @@ class Main extends eui.UILayer {
* Create scene interface
*/
protected createGameScene(): void {
- SceneManager.scene = new MainScene();
-
- // Main.emitter.addObserver(CoreEmitterType.Update, ()=>{
- // console.log("update emitter");
- // });
+ es.Core.scene = new scene.MainScene();
}
}
diff --git a/demo/src/game/CoreEmitterType.ts b/demo/src/game/CoreEmitterType.ts
deleted file mode 100644
index 6f845ce5..00000000
--- a/demo/src/game/CoreEmitterType.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-enum CoreEmitterType {
- Update,
-}
\ No newline at end of file
diff --git a/demo/src/game/MainScene.ts b/demo/src/game/MainScene.ts
index 94edd363..6a5b5550 100644
--- a/demo/src/game/MainScene.ts
+++ b/demo/src/game/MainScene.ts
@@ -1,86 +1,90 @@
-class MainScene extends Scene {
- constructor() {
- super();
+module scene {
+ export class MainScene extends es.Scene {
+ constructor() {
+ super();
- // this.addEntityProcessor(new SpawnerSystem(new Matcher()));
- this.astarTest();
- this.dijkstraTest();
- this.breadthfirstTest();
- }
-
- public async onStart() {
- let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
- let bg = this.createEntity("bg");
- bg.addComponent(new SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
- bg.addComponent(new PlayerController());
- bg.addComponent(new Mover());
- bg.addComponent(new BoxCollider());
- bg.position = new Vector2(300, 300);
-
- for (let i = 0; i < 1; i++) {
- let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
- let player2 = this.createEntity("player2");
- player2.addComponent(new SpriteRenderer()).setSprite(sprite);
- player2.position = new Vector2(200, 200);
- player2.addComponent(new BoxCollider());
+ // this.addEntityProcessor(new SpawnerSystem(new Matcher()));
+ this.astarTest();
+ this.dijkstraTest();
+ this.breadthfirstTest();
}
- this.camera.follow(bg, CameraStyle.lockOn);
+ public async onStart() {
+ let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
+ let bg = this.createEntity("bg");
+ bg.addComponent(new es.SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
+ bg.addComponent(new component.PlayerController());
+ bg.addComponent(new es.Mover());
+ bg.addComponent(new es.ScrollingSpriteRenderer(sprite));
+ bg.addComponent(new es.BoxCollider());
+ bg.position = new es.Vector2(Math.random() * 200, Math.random() * 200);
- let pool = new ComponentPool(SimplePooled);
- let c1 = pool.obtain();
- let c2 = pool.obtain();
- pool.free(c1);
- let c1b = pool.obtain();
+ for (let i = 0; i < 20; i++) {
+ let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
+ let player2 = this.createEntity("player2");
+ player2.addComponent(new es.SpriteRenderer()).setSprite(sprite);
+ player2.position = new es.Vector2(Math.random() * 1000, Math.random() * 1000);
+ player2.addComponent(new es.BoxCollider());
+ }
- console.log(c1 != c2);
- console.log(c1 == c1b);
+ this.camera.follow(bg, es.CameraStyle.lockOn);
- let button = new eui.Button();
- button.label = "切换场景";
- this.addChild(button);
- button.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
- SceneManager.startSceneTransition(new FadeTransition(() => {
- return new MainScene();
- }));
- }, this);
+ let pool = new es.ComponentPool(component.SimplePooled);
+ let c1 = pool.obtain();
+ let c2 = pool.obtain();
+ pool.free(c1);
+ let c1b = pool.obtain();
+
+ console.log(c1 != c2);
+ console.log(c1 == c1b);
+
+ let button = new eui.Button();
+ button.label = "切换场景";
+ this.addChild(button);
+ button.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
+ es.Core.startSceneTransition(new es.FadeTransition(() => {
+ return new MainScene();
+ }));
+ }, this);
+ }
+
+ public breadthfirstTest() {
+ let graph = new es.UnweightedGraph();
+
+ graph.addEdgesForNode("a", ["b"]); // a->b
+ graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d
+ graph.addEdgesForNode("c", ["a"]); // c->a
+ graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a
+ graph.addEdgesForNode("e", ["b"]); // e->b
+
+ // 计算从c到e的路径
+ let path = es.BreadthFirstPathfinder.search(graph, "c", "e");
+ console.log(path);
+ }
+
+ public dijkstraTest() {
+ let graph = new es.WeightedGridGraph(20, 20);
+
+ graph.weightedNodes.push(new es.Vector2(3, 3));
+ graph.weightedNodes.push(new es.Vector2(3, 4));
+ graph.weightedNodes.push(new es.Vector2(4, 3));
+ graph.weightedNodes.push(new es.Vector2(4, 4));
+
+ let path = graph.search(new es.Vector2(3, 4), new es.Vector2(15, 17));
+ console.log(path);
+ }
+
+ public astarTest() {
+ let graph = new es.AstarGridGraph(30, 30);
+
+ // graph.weightedNodes.push(new Vector2(3, 3));
+ // graph.weightedNodes.push(new Vector2(3, 4));
+ // graph.weightedNodes.push(new Vector2(4, 3));
+ // graph.weightedNodes.push(new Vector2(4, 4));
+
+ let startTime = egret.getTimer();
+ let path = graph.search(new es.Vector2(1, 1), new es.Vector2(29, 29));
+ console.log(egret.getTimer() - startTime);
+ }
}
-
- public breadthfirstTest() {
- let graph = new UnweightedGraph();
-
- graph.addEdgesForNode("a", ["b"]); // a->b
- graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d
- graph.addEdgesForNode("c", ["a"]); // c->a
- graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a
- graph.addEdgesForNode("e", ["b"]); // e->b
-
- // 计算从c到e的路径
- let path = BreadthFirstPathfinder.search(graph, "c", "e");
- console.log(path);
- }
-
- public dijkstraTest() {
- let graph = new WeightedGridGraph(20, 20);
-
- graph.weightedNodes.push(new Vector2(3, 3));
- graph.weightedNodes.push(new Vector2(3, 4));
- graph.weightedNodes.push(new Vector2(4, 3));
- graph.weightedNodes.push(new Vector2(4, 4));
-
- let path = graph.search(new Vector2(3, 4), new Vector2(15, 17));
- console.log(path);
- }
-
- public astarTest() {
- let graph = new AstarGridGraph(20, 20);
-
- graph.weightedNodes.push(new Vector2(3, 3));
- graph.weightedNodes.push(new Vector2(3, 4));
- graph.weightedNodes.push(new Vector2(4, 3));
- graph.weightedNodes.push(new Vector2(4, 4));
-
- let path = graph.search(new Vector2(3, 4), new Vector2(15, 17));
- console.log(path);
- }
-}
\ No newline at end of file
+}
diff --git a/demo/src/game/PlayerController.ts b/demo/src/game/PlayerController.ts
index 60d4bcf2..332fb945 100644
--- a/demo/src/game/PlayerController.ts
+++ b/demo/src/game/PlayerController.ts
@@ -1,56 +1,66 @@
-class PlayerController extends Component {
- private down: boolean = false;
- private touchPoint: Vector2 = Vector2.zero;
- private mover: Mover;
- private spriteRenderer: SpriteRenderer;
+module component {
+ import Component = es.Component;
+ import Vector2 = es.Vector2;
+ import Mover = es.Mover;
+ import SpriteRenderer = es.SpriteRenderer;
+ import Time = es.Time;
+ import Input = es.Input;
+ import CollisionResult = es.CollisionResult;
- public onAddedToEntity(){
- this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
- this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchBegin, this);
- this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
- }
+ export class PlayerController extends Component {
+ private down: boolean = false;
+ private touchPoint: Vector2 = Vector2.zero;
+ private mover: Mover;
+ private spriteRenderer: SpriteRenderer;
- private touchBegin(evt: egret.TouchEvent){
- this.down = true;
- this.touchPoint = new Vector2(evt.stageX, evt.stageY);
- }
+ public onAddedToEntity(){
+ this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
+ this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchBegin, this);
+ this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
+ }
- private touchEnd(evt: egret.TouchEvent){
- this.down = false;
- this.touchPoint = new Vector2(evt.stageX, evt.stageY);
- }
+ private touchBegin(evt: egret.TouchEvent){
+ this.down = true;
+ this.touchPoint = new Vector2(evt.stageX, evt.stageY);
+ }
- public update(){
- if (!this.mover)
- this.mover = this.entity.getComponent(Mover);
+ private touchEnd(evt: egret.TouchEvent){
+ this.down = false;
+ this.touchPoint = new Vector2(evt.stageX, evt.stageY);
+ }
- if (!this.spriteRenderer)
- this.spriteRenderer = this.entity.getComponent(SpriteRenderer);
+ public update(){
+ if (!this.mover)
+ this.mover = this.entity.getComponent(Mover);
- if (!this.mover)
- return;
+ if (!this.spriteRenderer)
+ this.spriteRenderer = this.entity.getComponent(SpriteRenderer);
- if (!SpriteRenderer)
- return;
+ if (!this.mover)
+ return;
- if (this.down){
- // let camera = SceneManager.scene.camera;
- // let moveLeft: number = 0;
- // let moveRight: number = 0;
- // let speed = 100;
- // let worldPos = Input.touchPosition;
- // if (worldPos.x < this.spriteRenderer.x){
- // moveLeft = -1;
- // } else if(worldPos.x > this.spriteRenderer.x){
- // moveLeft = 1;
- // }
+ if (!SpriteRenderer)
+ return;
- // if (worldPos.y < this.spriteRenderer.y){
- // moveRight = -1;
- // } else if(worldPos.y > this.spriteRenderer.y){
- // moveRight = 1;
- // }
- this.mover.move(new Vector2(-1, -1));
+ if (this.down){
+ let moveLeft: number = 0;
+ let moveRight: number = 0;
+ let speed = 100;
+ let worldPos = this.entity.scene.camera.mouseToWorldPoint();
+ if (worldPos.x < this.spriteRenderer.transform.position.x){
+ moveLeft = -1;
+ } else if(worldPos.x > this.spriteRenderer.transform.position.x){
+ moveLeft = 1;
+ }
+
+ if (worldPos.y < this.spriteRenderer.transform.position.y){
+ moveRight = -1;
+ } else if(worldPos.y > this.spriteRenderer.transform.position.y){
+ moveRight = 1;
+ }
+ let collisionResult = new CollisionResult();
+ this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime), collisionResult);
+ }
}
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/game/SimplePooled.ts b/demo/src/game/SimplePooled.ts
index c9345b4c..c455db33 100644
--- a/demo/src/game/SimplePooled.ts
+++ b/demo/src/game/SimplePooled.ts
@@ -1,5 +1,9 @@
-class SimplePooled extends PooledComponent {
- public reset(){
-
+module component {
+ import PooledComponent = es.PooledComponent;
+
+ export class SimplePooled extends PooledComponent {
+ public reset(){
+
+ }
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/game/SpawnerComponent.ts b/demo/src/game/SpawnerComponent.ts
index 381b8b14..fb50ee0e 100644
--- a/demo/src/game/SpawnerComponent.ts
+++ b/demo/src/game/SpawnerComponent.ts
@@ -1,35 +1,37 @@
-class SpawnComponent extends Component implements ITriggerListener {
- public cooldown = -1;
- public minInterval = 2;
- public maxInterval = 60;
- public enemyType = EnemyType.worm;
- public numSpawned = 0;
- public numAlive = 0;
+module component {
+ export class SpawnComponent extends es.Component implements es.ITriggerListener {
+ public cooldown = -1;
+ public minInterval = 2;
+ public maxInterval = 60;
+ public enemyType = EnemyType.worm;
+ public numSpawned = 0;
+ public numAlive = 0;
- constructor(enemyType: EnemyType) {
- super();
- this.enemyType = enemyType;
+ constructor(enemyType: EnemyType) {
+ super();
+ this.enemyType = enemyType;
+ }
+
+ public initialize() {
+ // console.log("initialize");
+ }
+
+ public update() {
+ // console.log("update");
+ }
+
+ public onTriggerEnter(other: es.Collider, local: es.Collider){
+ if (other == local)
+ console.log("repeat collider");
+ console.log("enter collider");
+ }
+
+ public onTriggerExit(other: es.Collider, local: es.Collider){
+ console.log("exit collider");
+ }
}
- public initialize() {
- // console.log("initialize");
- }
-
- public update() {
- // console.log("update");
- }
-
- public onTriggerEnter(other: Collider, local: Collider){
- if (other == local)
- console.log("repeat collider")
- console.log("enter collider");
- }
-
- public onTriggerExit(other: Collider, local: Collider){
- console.log("exit collider");
+ export enum EnemyType {
+ worm
}
}
-
-enum EnemyType {
- worm
-}
\ No newline at end of file
diff --git a/demo/src/game/SpawnerSystem.ts b/demo/src/game/SpawnerSystem.ts
index 019cbef2..fa3a418a 100644
--- a/demo/src/game/SpawnerSystem.ts
+++ b/demo/src/game/SpawnerSystem.ts
@@ -1,34 +1,36 @@
-class SpawnerSystem extends EntityProcessingSystem {
- constructor(matcher: Matcher){
- super(matcher);
- }
-
- public processEntity(entity: Entity){
- let spawner = entity.getComponent(SpawnComponent);
- if (!spawner)
- return;
-
- if (spawner.numAlive <= 0)
- spawner.enabled = true;
-
- if (!spawner.enabled)
- return;
-
- console.log("cooldown", spawner.cooldown);
- if (spawner.cooldown == -1){
- spawner.cooldown = Math.random() * 60;
- spawner.cooldown /= 4;
+module system {
+ export class SpawnerSystem extends es.EntityProcessingSystem {
+ constructor(matcher: es.Matcher){
+ super(matcher);
}
- spawner.cooldown -= Time.deltaTime;
- if (spawner.cooldown <= 0){
- spawner.cooldown = Math.random() * 60;
- // CreateEnemy
- spawner.numSpawned ++;
- spawner.numAlive ++;
+ public processEntity(entity: es.Entity){
+ let spawner = entity.getComponent(component.SpawnComponent);
+ if (!spawner)
+ return;
- if (spawner.numAlive > 0)
- spawner.enabled = false;
+ if (spawner.numAlive <= 0)
+ spawner.enabled = true;
+
+ if (!spawner.enabled)
+ return;
+
+ console.log("cooldown", spawner.cooldown);
+ if (spawner.cooldown == -1){
+ spawner.cooldown = Math.random() * 60;
+ spawner.cooldown /= 4;
+ }
+
+ spawner.cooldown -= es.Time.deltaTime;
+ if (spawner.cooldown <= 0){
+ spawner.cooldown = Math.random() * 60;
+ // CreateEnemy
+ spawner.numSpawned ++;
+ spawner.numAlive ++;
+
+ if (spawner.numAlive > 0)
+ spawner.enabled = false;
+ }
}
}
-}
\ No newline at end of file
+}
diff --git a/demo/template/runtime/native_require.js b/demo/template/runtime/native_require.js
index 62d691bf..3df96bc9 100644
--- a/demo/template/runtime/native_require.js
+++ b/demo/template/runtime/native_require.js
@@ -32,7 +32,7 @@ egret_native.egretStart = function () {
//The following is automatically modified, please do not modify
//----auto option start----
entryClassName: "Main",
- frameRate: 30,
+ frameRate: 60,
scaleMode: "fixedWidth",
contentWidth: 640,
contentHeight: 1136,
diff --git a/demo/tsconfig.json b/demo/tsconfig.json
index 5737e5ba..23bf9dbf 100644
--- a/demo/tsconfig.json
+++ b/demo/tsconfig.json
@@ -2,6 +2,7 @@
"compilerOptions": {
"target": "es5",
"outDir": "bin-debug",
+ "sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"lib": [
diff --git a/source/.vscode/tasks.json b/source/.vscode/tasks.json
index aba11758..8d24ee93 100644
--- a/source/.vscode/tasks.json
+++ b/source/.vscode/tasks.json
@@ -1,13 +1,13 @@
{
- // See https://go.microsoft.com/fwlink/?LinkId=733558
- // for the documentation about the tasks.json format
- "version": "2.0.0",
- "tasks": [
- {
- "type": "gulp",
- "task": "build",
- "group": "build",
- "problemMatcher": []
- }
- ]
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
+ // for the documentation about the tasks.json format
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "type": "gulp",
+ "task": "build",
+ "group": "build",
+ "problemMatcher": []
+ }
+ ]
}
\ No newline at end of file
diff --git a/source/.wing/settings.json b/source/.wing/settings.json
new file mode 100644
index 00000000..c3fcd996
--- /dev/null
+++ b/source/.wing/settings.json
@@ -0,0 +1,3 @@
+{
+ "typescript.tsdk": "./node_modules/typescript/lib"
+}
\ No newline at end of file
diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts
index a8d146ad..f8cf463e 100644
--- a/source/bin/framework.d.ts
+++ b/source/bin/framework.d.ts
@@ -1,1058 +1,1848 @@
declare interface Array {
- findIndex(predicate: Function): number;
- any(predicate: Function): boolean;
- firstOrDefault(predicate: Function): T;
- find(predicate: Function): T;
- where(predicate: Function): Array;
- count(predicate: Function): number;
- findAll(predicate: Function): Array;
- contains(value: any): boolean;
- removeAll(predicate: Function): void;
- remove(element: any): boolean;
- removeAt(index: any): void;
- removeRange(index: any, count: any): void;
+ findIndex(predicate: (c: T) => boolean): number;
+ any(predicate: (c: T) => boolean): boolean;
+ firstOrDefault(predicate: (c: T) => boolean): T;
+ find(predicate: (c: T) => boolean): T;
+ where(predicate: (c: T) => boolean): Array;
+ count(predicate: (c: T) => boolean): number;
+ findAll(predicate: (c: T) => boolean): Array;
+ contains(value: T): boolean;
+ removeAll(predicate: (c: T) => boolean): void;
+ remove(element: T): boolean;
+ removeAt(index: number): void;
+ removeRange(index: number, count: number): void;
select(selector: Function): Array;
orderBy(keySelector: Function, comparer: Function): Array;
orderByDescending(keySelector: Function, comparer: Function): Array;
groupBy(keySelector: Function): Array;
- sum(selector: any): any;
-}
-declare class PriorityQueueNode {
- priority: number;
- insertionIndex: number;
- queueIndex: number;
-}
-declare class AStarPathfinder {
- static search(graph: IAstarGraph, start: T, goal: T): T[];
- private static hasKey;
- private static getKey;
- static recontructPath