Merge branch 'develop' of https://github.com/esengine/egret-framework into develop
This commit is contained in:
151
source/bin/framework.d.ts
vendored
151
source/bin/framework.d.ts
vendored
@@ -32,22 +32,22 @@ declare class AStarNode<T> extends PriorityQueueNode {
|
||||
data: T;
|
||||
constructor(data: T);
|
||||
}
|
||||
declare class AstarGridGraph implements IAstarGraph<Point> {
|
||||
dirs: Point[];
|
||||
walls: Point[];
|
||||
weightedNodes: Point[];
|
||||
declare class AstarGridGraph implements IAstarGraph<Vector2> {
|
||||
dirs: Vector2[];
|
||||
walls: Vector2[];
|
||||
weightedNodes: Vector2[];
|
||||
defaultWeight: number;
|
||||
weightedNodeWeight: number;
|
||||
private _width;
|
||||
private _height;
|
||||
private _neighbors;
|
||||
constructor(width: number, height: number);
|
||||
isNodeInBounds(node: Point): boolean;
|
||||
isNodePassable(node: Point): boolean;
|
||||
search(start: Point, goal: Point): Point[];
|
||||
getNeighbors(node: Point): Point[];
|
||||
cost(from: Point, to: Point): number;
|
||||
heuristic(node: Point, goal: Point): 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<T> {
|
||||
getNeighbors(node: T): Array<T>;
|
||||
@@ -84,34 +84,57 @@ declare class UnweightedGraph<T> implements IUnweightedGraph<T> {
|
||||
addEdgesForNode(node: T, edges: T[]): this;
|
||||
getNeighbors(node: T): T[];
|
||||
}
|
||||
declare class Point {
|
||||
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<Point> {
|
||||
declare class UnweightedGridGraph implements IUnweightedGraph<Vector2> {
|
||||
private static readonly CARDINAL_DIRS;
|
||||
private static readonly COMPASS_DIRS;
|
||||
walls: Point[];
|
||||
walls: Vector2[];
|
||||
private _width;
|
||||
private _hegiht;
|
||||
private _dirs;
|
||||
private _neighbors;
|
||||
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
||||
isNodeInBounds(node: Point): boolean;
|
||||
isNodePassable(node: Point): boolean;
|
||||
getNeighbors(node: Point): Point[];
|
||||
search(start: Point, goal: Point): Point[];
|
||||
isNodeInBounds(node: Vector2): boolean;
|
||||
isNodePassable(node: Vector2): boolean;
|
||||
getNeighbors(node: Vector2): Vector2[];
|
||||
search(start: Vector2, goal: Vector2): Vector2[];
|
||||
}
|
||||
interface IWeightedGraph<T> {
|
||||
getNeighbors(node: T): T[];
|
||||
cost(from: T, to: T): number;
|
||||
}
|
||||
declare class WeightedGridGraph implements IWeightedGraph<Point> {
|
||||
static readonly CARDINAL_DIRS: Point[];
|
||||
declare class WeightedGridGraph implements IWeightedGraph<Vector2> {
|
||||
static readonly CARDINAL_DIRS: Vector2[];
|
||||
private static readonly COMPASS_DIRS;
|
||||
walls: Point[];
|
||||
weightedNodes: Point[];
|
||||
walls: Vector2[];
|
||||
weightedNodes: Vector2[];
|
||||
defaultWeight: number;
|
||||
weightedNodeWeight: number;
|
||||
private _width;
|
||||
@@ -119,11 +142,11 @@ declare class WeightedGridGraph implements IWeightedGraph<Point> {
|
||||
private _dirs;
|
||||
private _neighbors;
|
||||
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
||||
isNodeInBounds(node: Point): boolean;
|
||||
isNodePassable(node: Point): boolean;
|
||||
search(start: Point, goal: Point): Point[];
|
||||
getNeighbors(node: Point): Point[];
|
||||
cost(from: Point, to: Point): 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;
|
||||
}
|
||||
declare class WeightedNode<T> extends PriorityQueueNode {
|
||||
data: T;
|
||||
@@ -153,12 +176,12 @@ declare abstract class Component extends egret.DisplayObjectContainer {
|
||||
onDisabled(): void;
|
||||
update(): void;
|
||||
debugRender(): void;
|
||||
onEntityTransformChanged(comp: TransformComponent): void;
|
||||
registerComponent(): void;
|
||||
deregisterComponent(): void;
|
||||
}
|
||||
declare class Entity extends egret.DisplayObjectContainer {
|
||||
private static _idGenerator;
|
||||
private _position;
|
||||
name: string;
|
||||
readonly id: number;
|
||||
scene: Scene;
|
||||
@@ -171,6 +194,7 @@ declare class Entity extends egret.DisplayObjectContainer {
|
||||
readonly isDestoryed: boolean;
|
||||
position: Vector2;
|
||||
scale: Vector2;
|
||||
rotation: number;
|
||||
enabled: boolean;
|
||||
setEnabled(isEnabled: boolean): this;
|
||||
tag: number;
|
||||
@@ -187,6 +211,7 @@ declare class Entity extends egret.DisplayObjectContainer {
|
||||
getOrCreateComponent<T extends Component>(type: T): T;
|
||||
getComponent<T extends Component>(type: any): T;
|
||||
getComponents(typeName: string | any, componentList?: any): any;
|
||||
private onEntityTransformChanged;
|
||||
removeComponentForType<T extends Component>(type: any): boolean;
|
||||
removeComponent(component: Component): void;
|
||||
removeAllComponents(): void;
|
||||
@@ -195,6 +220,11 @@ declare class Entity extends egret.DisplayObjectContainer {
|
||||
onRemovedFromScene(): void;
|
||||
destroy(): void;
|
||||
}
|
||||
declare enum TransformComponent {
|
||||
rotation = 0,
|
||||
scale = 1,
|
||||
position = 2
|
||||
}
|
||||
declare class Scene extends egret.DisplayObjectContainer {
|
||||
camera: Camera;
|
||||
readonly entities: EntityList;
|
||||
@@ -244,6 +274,7 @@ declare class Camera extends Component {
|
||||
private _origin;
|
||||
private _minimumZoom;
|
||||
private _maximumZoom;
|
||||
private _position;
|
||||
followLerp: number;
|
||||
deadzone: Rectangle;
|
||||
focusOffset: Vector2;
|
||||
@@ -259,6 +290,8 @@ declare class Camera extends Component {
|
||||
maximumZoom: number;
|
||||
origin: Vector2;
|
||||
position: Vector2;
|
||||
x: number;
|
||||
y: number;
|
||||
constructor();
|
||||
onSceneSizeChanged(newWidth: number, newHeight: number): void;
|
||||
setMinimumZoom(minZoom: number): Camera;
|
||||
@@ -312,11 +345,8 @@ declare class Mesh extends RenderableComponent {
|
||||
reset(): void;
|
||||
}
|
||||
declare class SpriteRenderer extends RenderableComponent {
|
||||
private _origin;
|
||||
private _sprite;
|
||||
protected bitmap: egret.Bitmap;
|
||||
origin: Vector2;
|
||||
setOrigin(origin: Vector2): this;
|
||||
sprite: Sprite;
|
||||
setSprite(sprite: Sprite): SpriteRenderer;
|
||||
setColor(color: number): SpriteRenderer;
|
||||
@@ -406,11 +436,9 @@ declare abstract class Collider extends Component {
|
||||
physicsLayer: number;
|
||||
isTrigger: boolean;
|
||||
registeredPhysicsBounds: Rectangle;
|
||||
shouldColliderScaleAndRotationWithTransform: boolean;
|
||||
shouldColliderScaleAndRotateWithTransform: boolean;
|
||||
collidesWithLayers: number;
|
||||
_localOffsetLength: number;
|
||||
_isPositionDirty: boolean;
|
||||
_isRotationDirty: boolean;
|
||||
protected _isParentEntityAddedToScene: any;
|
||||
protected _colliderRequiresAutoSizing: any;
|
||||
protected _localOffset: Vector2;
|
||||
@@ -426,6 +454,7 @@ declare abstract class Collider extends Component {
|
||||
onRemovedFromEntity(): void;
|
||||
onEnabled(): void;
|
||||
onDisabled(): void;
|
||||
onEntityTransformChanged(comp: TransformComponent): void;
|
||||
}
|
||||
declare class BoxCollider extends Collider {
|
||||
width: number;
|
||||
@@ -501,6 +530,7 @@ declare class ComponentList {
|
||||
deregisterAllComponents(): void;
|
||||
registerAllComponents(): void;
|
||||
updateLists(): void;
|
||||
onEntityTransformChanged(comp: TransformComponent): void;
|
||||
private handleRemove;
|
||||
getComponent<T extends Component>(type: any, onlyReturnInitializedComponents: boolean): T;
|
||||
getComponents(typeName: string | any, components?: any): any;
|
||||
@@ -743,68 +773,29 @@ declare class 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, 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 {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
private _tempMat;
|
||||
private _transformMat;
|
||||
declare class Rectangle extends egret.Rectangle {
|
||||
readonly max: Vector2;
|
||||
readonly left: number;
|
||||
readonly right: number;
|
||||
readonly top: number;
|
||||
readonly bottom: number;
|
||||
readonly center: Vector2;
|
||||
location: Vector2;
|
||||
size: Vector2;
|
||||
constructor(x?: number, y?: number, width?: number, height?: number);
|
||||
intersects(value: Rectangle): boolean;
|
||||
contains(value: Vector2): boolean;
|
||||
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: Point): {
|
||||
getClosestPointOnRectangleBorderToPoint(point: Vector2): {
|
||||
res: Vector2;
|
||||
edgeNormal: Vector2;
|
||||
};
|
||||
getClosestPointOnBoundsToOrigin(): Vector2;
|
||||
calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
|
||||
static rectEncompassingPoints(points: Vector2[]): Rectangle;
|
||||
}
|
||||
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 Vector3 {
|
||||
x: number;
|
||||
y: number;
|
||||
@@ -937,7 +928,7 @@ declare class ShapeCollisions {
|
||||
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): false | CollisionResult;
|
||||
static boxToBox(first: Box, second: Box): CollisionResult;
|
||||
private static minkowskiDifference;
|
||||
}
|
||||
declare class SpatialHash {
|
||||
@@ -1044,7 +1035,7 @@ declare class Pair<T> {
|
||||
equals(other: Pair<T>): boolean;
|
||||
}
|
||||
declare class RectangleExt {
|
||||
static union(first: Rectangle, point: Point): Rectangle;
|
||||
static union(first: Rectangle, point: Vector2): Rectangle;
|
||||
static unionR(value1: Rectangle, value2: Rectangle): Rectangle;
|
||||
}
|
||||
declare class Triangulator {
|
||||
|
||||
@@ -361,10 +361,10 @@ var AStarNode = (function (_super) {
|
||||
var AstarGridGraph = (function () {
|
||||
function AstarGridGraph(width, height) {
|
||||
this.dirs = [
|
||||
new Point(1, 0),
|
||||
new Point(0, -1),
|
||||
new Point(-1, 0),
|
||||
new Point(0, 1)
|
||||
new Vector2(1, 0),
|
||||
new Vector2(0, -1),
|
||||
new Vector2(-1, 0),
|
||||
new Vector2(0, 1)
|
||||
];
|
||||
this.walls = [];
|
||||
this.weightedNodes = [];
|
||||
@@ -387,7 +387,7 @@ var AstarGridGraph = (function () {
|
||||
var _this = this;
|
||||
this._neighbors.length = 0;
|
||||
this.dirs.forEach(function (dir) {
|
||||
var next = new Point(node.x + dir.x, node.y + dir.y);
|
||||
var next = new Vector2(node.x + dir.x, node.y + dir.y);
|
||||
if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
|
||||
_this._neighbors.push(next);
|
||||
});
|
||||
@@ -583,12 +583,113 @@ var UnweightedGraph = (function () {
|
||||
};
|
||||
return UnweightedGraph;
|
||||
}());
|
||||
var Point = (function () {
|
||||
function Point(x, y) {
|
||||
var Vector2 = (function () {
|
||||
function Vector2(x, y) {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.x = x ? x : 0;
|
||||
this.y = y ? y : this.x;
|
||||
}
|
||||
return Point;
|
||||
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) {
|
||||
@@ -609,7 +710,7 @@ var UnweightedGridGraph = (function () {
|
||||
var _this = this;
|
||||
this._neighbors.length = 0;
|
||||
this._dirs.forEach(function (dir) {
|
||||
var next = new Point(node.x + dir.x, node.y + dir.y);
|
||||
var next = new Vector2(node.x + dir.x, node.y + dir.y);
|
||||
if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
|
||||
_this._neighbors.push(next);
|
||||
});
|
||||
@@ -619,20 +720,20 @@ var UnweightedGridGraph = (function () {
|
||||
return BreadthFirstPathfinder.search(this, start, goal);
|
||||
};
|
||||
UnweightedGridGraph.CARDINAL_DIRS = [
|
||||
new Point(1, 0),
|
||||
new Point(0, -1),
|
||||
new Point(-1, 0),
|
||||
new Point(0, -1)
|
||||
new Vector2(1, 0),
|
||||
new Vector2(0, -1),
|
||||
new Vector2(-1, 0),
|
||||
new Vector2(0, -1)
|
||||
];
|
||||
UnweightedGridGraph.COMPASS_DIRS = [
|
||||
new Point(1, 0),
|
||||
new Point(1, -1),
|
||||
new Point(0, -1),
|
||||
new Point(-1, -1),
|
||||
new Point(-1, 0),
|
||||
new Point(-1, 1),
|
||||
new Point(0, 1),
|
||||
new Point(1, 1),
|
||||
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;
|
||||
}());
|
||||
@@ -661,7 +762,7 @@ var WeightedGridGraph = (function () {
|
||||
var _this = this;
|
||||
this._neighbors.length = 0;
|
||||
this._dirs.forEach(function (dir) {
|
||||
var next = new Point(node.x + dir.x, node.y + dir.y);
|
||||
var next = new Vector2(node.x + dir.x, node.y + dir.y);
|
||||
if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
|
||||
_this._neighbors.push(next);
|
||||
});
|
||||
@@ -671,20 +772,20 @@ var WeightedGridGraph = (function () {
|
||||
return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight;
|
||||
};
|
||||
WeightedGridGraph.CARDINAL_DIRS = [
|
||||
new Point(1, 0),
|
||||
new Point(0, -1),
|
||||
new Point(-1, 0),
|
||||
new Point(0, 1)
|
||||
new Vector2(1, 0),
|
||||
new Vector2(0, -1),
|
||||
new Vector2(-1, 0),
|
||||
new Vector2(0, 1)
|
||||
];
|
||||
WeightedGridGraph.COMPASS_DIRS = [
|
||||
new Point(1, 0),
|
||||
new Point(1, -1),
|
||||
new Point(0, -1),
|
||||
new Point(-1, -1),
|
||||
new Point(-1, 0),
|
||||
new Point(-1, 1),
|
||||
new Point(0, 1),
|
||||
new Point(1, 1),
|
||||
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;
|
||||
}());
|
||||
@@ -816,6 +917,8 @@ var Component = (function (_super) {
|
||||
};
|
||||
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);
|
||||
@@ -830,7 +933,6 @@ var Entity = (function (_super) {
|
||||
__extends(Entity, _super);
|
||||
function Entity(name) {
|
||||
var _this = _super.call(this) || this;
|
||||
_this._position = Vector2.zero;
|
||||
_this._updateOrder = 0;
|
||||
_this._enabled = true;
|
||||
_this._tag = 0;
|
||||
@@ -849,10 +951,12 @@ var Entity = (function (_super) {
|
||||
});
|
||||
Object.defineProperty(Entity.prototype, "position", {
|
||||
get: function () {
|
||||
return this._position;
|
||||
return new Vector2(this.x, this.y);
|
||||
},
|
||||
set: function (value) {
|
||||
this._position = value;
|
||||
this.$setX(value.x);
|
||||
this.$setY(value.y);
|
||||
this.onEntityTransformChanged(TransformComponent.position);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
@@ -862,8 +966,17 @@ var Entity = (function (_super) {
|
||||
return new Vector2(this.scaleX, this.scaleY);
|
||||
},
|
||||
set: function (value) {
|
||||
this.scaleX = value.x;
|
||||
this.scaleY = value.y;
|
||||
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
|
||||
@@ -973,6 +1086,9 @@ var Entity = (function (_super) {
|
||||
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) {
|
||||
@@ -1009,6 +1125,12 @@ var Entity = (function (_super) {
|
||||
};
|
||||
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() {
|
||||
@@ -1112,6 +1234,8 @@ var Scene = (function (_super) {
|
||||
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 () {
|
||||
@@ -1251,6 +1375,7 @@ var Camera = (function (_super) {
|
||||
_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();
|
||||
@@ -1312,10 +1437,30 @@ var Camera = (function (_super) {
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "position", {
|
||||
get: function () {
|
||||
return this.entity.position;
|
||||
return this._position;
|
||||
},
|
||||
set: function (value) {
|
||||
this.entity.position = 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
|
||||
@@ -1553,22 +1698,6 @@ var SpriteRenderer = (function (_super) {
|
||||
function SpriteRenderer() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
Object.defineProperty(SpriteRenderer.prototype, "origin", {
|
||||
get: function () {
|
||||
return this._origin;
|
||||
},
|
||||
set: function (value) {
|
||||
this.setOrigin(value);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
SpriteRenderer.prototype.setOrigin = function (origin) {
|
||||
if (this._origin != origin) {
|
||||
this._origin = origin;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
Object.defineProperty(SpriteRenderer.prototype, "sprite", {
|
||||
get: function () {
|
||||
return this._sprite;
|
||||
@@ -1582,8 +1711,10 @@ var SpriteRenderer = (function (_super) {
|
||||
SpriteRenderer.prototype.setSprite = function (sprite) {
|
||||
this.removeChildren();
|
||||
this._sprite = sprite;
|
||||
if (this._sprite)
|
||||
this._origin = this._sprite.origin;
|
||||
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;
|
||||
@@ -1608,8 +1739,8 @@ var SpriteRenderer = (function (_super) {
|
||||
return this.isVisible;
|
||||
};
|
||||
SpriteRenderer.prototype.render = function (camera) {
|
||||
this.x = this.entity.position.x - this.origin.x - camera.position.x + camera.origin.x;
|
||||
this.y = this.entity.position.y - this.origin.y - camera.position.y + camera.origin.y;
|
||||
this.x = -camera.position.x + camera.origin.x;
|
||||
this.y = -camera.position.y + camera.origin.y;
|
||||
};
|
||||
SpriteRenderer.prototype.onRemovedFromEntity = function () {
|
||||
if (this.parent)
|
||||
@@ -1874,27 +2005,23 @@ var Collider = (function (_super) {
|
||||
function Collider() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.physicsLayer = 1 << 0;
|
||||
_this.shouldColliderScaleAndRotationWithTransform = true;
|
||||
_this.registeredPhysicsBounds = new Rectangle();
|
||||
_this.shouldColliderScaleAndRotateWithTransform = true;
|
||||
_this.collidesWithLayers = Physics.allLayers;
|
||||
_this._isPositionDirty = true;
|
||||
_this._isRotationDirty = true;
|
||||
_this._localOffset = new Vector2(0, 0);
|
||||
return _this;
|
||||
}
|
||||
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;
|
||||
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 this._localOffset;
|
||||
return new Vector2(this.x, this.y);
|
||||
},
|
||||
set: function (value) {
|
||||
this.setLocalOffset(value);
|
||||
@@ -1905,9 +2032,9 @@ var Collider = (function (_super) {
|
||||
Collider.prototype.setLocalOffset = function (offset) {
|
||||
if (this._localOffset != offset) {
|
||||
this.unregisterColliderWithPhysicsSystem();
|
||||
this._localOffset = offset;
|
||||
this.$setX(offset.x);
|
||||
this.$setY(offset.y);
|
||||
this._localOffsetLength = this._localOffset.length();
|
||||
this._isPositionDirty = true;
|
||||
this.registerColliderWithPhysicsSystem();
|
||||
}
|
||||
};
|
||||
@@ -1940,17 +2067,15 @@ var Collider = (function (_super) {
|
||||
if (!(this instanceof BoxCollider)) {
|
||||
console.error("Only box and circle colliders can be created automatically");
|
||||
}
|
||||
var renderable = this.entity.getComponent(RenderableComponent);
|
||||
if (renderable) {
|
||||
var renderbaleBounds = renderable.bounds;
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
this._isParentEntityAddedToScene = true;
|
||||
@@ -1962,11 +2087,14 @@ var Collider = (function (_super) {
|
||||
};
|
||||
Collider.prototype.onEnabled = function () {
|
||||
this.registerColliderWithPhysicsSystem();
|
||||
this._isPositionDirty = this._isRotationDirty = true;
|
||||
};
|
||||
Collider.prototype.onDisabled = function () {
|
||||
this.unregisterColliderWithPhysicsSystem();
|
||||
};
|
||||
Collider.prototype.onEntityTransformChanged = function (comp) {
|
||||
if (this._isColliderRegistered)
|
||||
Physics.updateCollider(this);
|
||||
};
|
||||
return Collider;
|
||||
}(Component));
|
||||
var BoxCollider = (function (_super) {
|
||||
@@ -1992,7 +2120,6 @@ var BoxCollider = (function (_super) {
|
||||
var box = this.shape;
|
||||
if (width != box.width) {
|
||||
box.updateBox(width, box.height);
|
||||
this._isPositionDirty = true;
|
||||
if (this.entity && this._isParentEntityAddedToScene)
|
||||
Physics.updateCollider(this);
|
||||
}
|
||||
@@ -2013,7 +2140,6 @@ var BoxCollider = (function (_super) {
|
||||
var box = this.shape;
|
||||
if (height != box.height) {
|
||||
box.updateBox(box.width, height);
|
||||
this._isPositionDirty = true;
|
||||
if (this.entity && this._isParentEntityAddedToScene)
|
||||
Physics.updateCollider(this);
|
||||
}
|
||||
@@ -2023,7 +2149,6 @@ var BoxCollider = (function (_super) {
|
||||
var box = this.shape;
|
||||
if (width != box.width || height != box.height) {
|
||||
box.updateBox(width, height);
|
||||
this._isPositionDirty = true;
|
||||
if (this.entity && this._isParentEntityAddedToScene)
|
||||
Physics.updateCollider(this);
|
||||
}
|
||||
@@ -2334,6 +2459,16 @@ var ComponentList = (function () {
|
||||
this._tempBufferList.length = 0;
|
||||
}
|
||||
};
|
||||
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.handleRemove = function (component) {
|
||||
if (component instanceof RenderableComponent)
|
||||
this._entity.scene.renderableComponents.remove(component);
|
||||
@@ -3340,8 +3475,8 @@ var Matrix2D = (function () {
|
||||
result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det;
|
||||
return result;
|
||||
};
|
||||
Matrix2D.createTranslation = function (xPosition, yPosition, result) {
|
||||
result = result ? result : new Matrix2D();
|
||||
Matrix2D.createTranslation = function (xPosition, yPosition) {
|
||||
var result = new Matrix2D();
|
||||
result.m11 = 1;
|
||||
result.m12 = 0;
|
||||
result.m21 = 0;
|
||||
@@ -3350,6 +3485,9 @@ var Matrix2D = (function () {
|
||||
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);
|
||||
@@ -3377,12 +3515,10 @@ var Matrix2D = (function () {
|
||||
Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0);
|
||||
return Matrix2D;
|
||||
}());
|
||||
var Rectangle = (function () {
|
||||
function Rectangle(x, y, width, height) {
|
||||
this.x = x ? x : 0;
|
||||
this.y = y ? y : 0;
|
||||
this.width = width ? width : 0;
|
||||
this.height = height ? height : 0;
|
||||
var Rectangle = (function (_super) {
|
||||
__extends(Rectangle, _super);
|
||||
function Rectangle() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
Object.defineProperty(Rectangle.prototype, "max", {
|
||||
get: function () {
|
||||
@@ -3391,34 +3527,6 @@ var Rectangle = (function () {
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "left", {
|
||||
get: function () {
|
||||
return this.x;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "right", {
|
||||
get: function () {
|
||||
return this.x + this.width;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "top", {
|
||||
get: function () {
|
||||
return this.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "bottom", {
|
||||
get: function () {
|
||||
return this.y + this.height;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "center", {
|
||||
get: function () {
|
||||
return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2));
|
||||
@@ -3454,7 +3562,7 @@ var Rectangle = (function () {
|
||||
value.top < this.bottom &&
|
||||
this.top < value.bottom;
|
||||
};
|
||||
Rectangle.prototype.contains = function (value) {
|
||||
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)));
|
||||
@@ -3471,11 +3579,11 @@ var Rectangle = (function () {
|
||||
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
||||
};
|
||||
Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) {
|
||||
var edgeNormal = new Vector2(0, 0);
|
||||
var res = new Vector2(0, 0);
|
||||
var edgeNormal = Vector2.zero;
|
||||
var res = new Vector2();
|
||||
res.x = MathHelper.clamp(point.x, this.left, this.right);
|
||||
res.y = MathHelper.clamp(point.y, this.top, this.bottom);
|
||||
if (this.contains(res)) {
|
||||
if (this.containsInVec(res)) {
|
||||
var dl = res.x - this.left;
|
||||
var dr = this.right - res.x;
|
||||
var dt = res.y - this.top;
|
||||
@@ -3499,18 +3607,14 @@ var Rectangle = (function () {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (res.x == this.left) {
|
||||
if (res.x == this.left)
|
||||
edgeNormal.x = -1;
|
||||
}
|
||||
if (res.x == this.right) {
|
||||
if (res.x == this.right)
|
||||
edgeNormal.x = 1;
|
||||
}
|
||||
if (res.y == this.top) {
|
||||
if (res.y == this.top)
|
||||
edgeNormal.y = -1;
|
||||
}
|
||||
if (res.y == this.bottom) {
|
||||
if (res.y == this.bottom)
|
||||
edgeNormal.y = 1;
|
||||
}
|
||||
}
|
||||
return { res: res, edgeNormal: edgeNormal };
|
||||
};
|
||||
@@ -3535,40 +3639,6 @@ var Rectangle = (function () {
|
||||
}
|
||||
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 = Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y);
|
||||
this._tempMat = Matrix2D.createScale(scale.x, scale.y);
|
||||
this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
|
||||
this._tempMat = Matrix2D.createRotation(rotation);
|
||||
this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
|
||||
this._tempMat = Matrix2D.createTranslation(worldPosX, worldPosY);
|
||||
this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
|
||||
var topLeft = new Vector2(worldPosX, worldPosY);
|
||||
var topRight = new Vector2(worldPosX + width, worldPosY);
|
||||
var bottomLeft = new Vector2(worldPosX, worldPosY + height);
|
||||
var bottomRight = new Vector2(worldPosX + width, worldPosY + height);
|
||||
topLeft = Vector2Ext.transformR(topLeft, this._transformMat);
|
||||
topRight = Vector2Ext.transformR(topRight, this._transformMat);
|
||||
bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat);
|
||||
bottomRight = 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 Vector2(minX, minY);
|
||||
this.width = maxX - minX;
|
||||
this.height = maxY - minY;
|
||||
}
|
||||
};
|
||||
Rectangle.rectEncompassingPoints = function (points) {
|
||||
var minX = Number.POSITIVE_INFINITY;
|
||||
var minY = Number.POSITIVE_INFINITY;
|
||||
@@ -3576,131 +3646,19 @@ var Rectangle = (function () {
|
||||
var maxY = Number.NEGATIVE_INFINITY;
|
||||
for (var i = 0; i < points.length; i++) {
|
||||
var pt = points[i];
|
||||
if (pt.x < minX) {
|
||||
if (pt.x < minX)
|
||||
minX = pt.x;
|
||||
}
|
||||
if (pt.x > maxX) {
|
||||
if (pt.x > maxX)
|
||||
maxX = pt.x;
|
||||
}
|
||||
if (pt.y < minY) {
|
||||
if (pt.y < minY)
|
||||
minY = pt.y;
|
||||
}
|
||||
if (pt.y > maxY) {
|
||||
if (pt.y > maxY)
|
||||
maxY = pt.y;
|
||||
}
|
||||
}
|
||||
return this.fromMinMax(minX, minY, maxX, maxY);
|
||||
};
|
||||
return Rectangle;
|
||||
}());
|
||||
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;
|
||||
}());
|
||||
}(egret.Rectangle));
|
||||
var Vector3 = (function () {
|
||||
function Vector3(x, y, z) {
|
||||
this.x = x;
|
||||
@@ -4099,7 +4057,7 @@ var Polygon = (function (_super) {
|
||||
};
|
||||
Polygon.prototype.recalculateBounds = function (collider) {
|
||||
this.center = collider.localOffset;
|
||||
if (collider.shouldColliderScaleAndRotationWithTransform) {
|
||||
if (collider.shouldColliderScaleAndRotateWithTransform) {
|
||||
var hasUnitScale = true;
|
||||
var tempMat = void 0;
|
||||
var combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y);
|
||||
@@ -4111,7 +4069,7 @@ var Polygon = (function (_super) {
|
||||
this.center = scaledOffset;
|
||||
}
|
||||
if (collider.entity.rotation != 0) {
|
||||
tempMat = Matrix2D.createRotation(collider.entity.rotation);
|
||||
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();
|
||||
@@ -4121,8 +4079,6 @@ var Polygon = (function (_super) {
|
||||
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
|
||||
Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points);
|
||||
this.isUnrotated = collider.entity.rotation == 0;
|
||||
if (collider._isRotationDirty)
|
||||
this._areEdgeNormalsDirty = true;
|
||||
}
|
||||
this.position = Vector2.add(collider.entity.position, this.center);
|
||||
this.bounds = Rectangle.rectEncompassingPoints(this.points);
|
||||
@@ -4177,7 +4133,7 @@ var Box = (function (_super) {
|
||||
};
|
||||
Box.prototype.containsPoint = function (point) {
|
||||
if (this.isUnrotated)
|
||||
return this.bounds.contains(point);
|
||||
return this.bounds.containsInVec(point);
|
||||
return _super.prototype.containsPoint.call(this, point);
|
||||
};
|
||||
return Box;
|
||||
@@ -4207,7 +4163,7 @@ var Circle = (function (_super) {
|
||||
};
|
||||
Circle.prototype.recalculateBounds = function (collider) {
|
||||
this.center = collider.localOffset;
|
||||
if (collider.shouldColliderScaleAndRotationWithTransform) {
|
||||
if (collider.shouldColliderScaleAndRotateWithTransform) {
|
||||
var scale = collider.entity.scale;
|
||||
var hasUnitScale = scale.x == 1 && scale.y == 1;
|
||||
var maxScale = Math.max(scale.x, scale.y);
|
||||
@@ -4291,7 +4247,7 @@ var ShapeCollisions = (function () {
|
||||
}
|
||||
}
|
||||
result.normal = translationAxis;
|
||||
result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis), new Vector2(minIntervalDistance));
|
||||
result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance));
|
||||
return result;
|
||||
};
|
||||
ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) {
|
||||
@@ -4414,10 +4370,10 @@ var ShapeCollisions = (function () {
|
||||
ShapeCollisions.boxToBox = function (first, second) {
|
||||
var result = new CollisionResult();
|
||||
var minkowskiDiff = this.minkowskiDifference(first, second);
|
||||
if (minkowskiDiff.contains(new Vector2(0, 0))) {
|
||||
if (minkowskiDiff.containsInVec(new Vector2(0, 0))) {
|
||||
result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin();
|
||||
if (result.minimumTranslationVector == Vector2.zero)
|
||||
return false;
|
||||
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;
|
||||
@@ -4436,6 +4392,7 @@ 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;
|
||||
@@ -4461,10 +4418,10 @@ var SpatialHash = (function () {
|
||||
collider.registeredPhysicsBounds = bounds;
|
||||
var p1 = this.cellCoords(bounds.x, bounds.y);
|
||||
var p2 = this.cellCoords(bounds.right, bounds.bottom);
|
||||
if (!this.gridBounds.contains(new Vector2(p1.x, p1.y))) {
|
||||
if (!this.gridBounds.containsInVec(new Vector2(p1.x, p1.y))) {
|
||||
this.gridBounds = RectangleExt.union(this.gridBounds, p1);
|
||||
}
|
||||
if (!this.gridBounds.contains(new Vector2(p2.x, p2.y))) {
|
||||
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++) {
|
||||
@@ -4533,7 +4490,7 @@ var SpatialHash = (function () {
|
||||
return cell;
|
||||
};
|
||||
SpatialHash.prototype.cellCoords = function (x, y) {
|
||||
return new Point(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
|
||||
return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
|
||||
};
|
||||
return SpatialHash;
|
||||
}());
|
||||
|
||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user