dragonbones-runtime
Version:
the tools to build dragonbones file for diffrent framework
1,466 lines • 537 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var dragonBones;
(function (dragonBones) {
})(dragonBones || (dragonBones = {}));
var dragonBones;
(function (dragonBones) {
/**
* @private
*/
var DragonBones = (function () {
function DragonBones(eventManager) {
this._clock = new dragonBones.WorldClock();
this._events = [];
this._objects = [];
this._eventManager = null;
this._eventManager = eventManager;
console.info("DragonBones: " + DragonBones.VERSION + "\nWebsite: http://www.dragonbones.com/\nSource: http://www.github.com/dragonbones/");
}
DragonBones.prototype.advanceTime = function (passedTime) {
if (this._objects.length > 0) {
for (var _i = 0, _a = this._objects; _i < _a.length; _i++) {
var object = _a[_i];
object.returnToPool();
}
this._objects.length = 0;
}
this._clock.advanceTime(passedTime);
if (this._events.length > 0) {
for (var i = 0; i < this._events.length; ++i) {
var eventObject = this._events[i];
var armature = eventObject.armature;
if (armature.armatureData !== null) {
armature.eventDispatcher._dispatchEvent(eventObject.type, eventObject);
if (eventObject.type === dragonBones.EventObject.SOUND_EVENT) {
this._eventManager._dispatchEvent(eventObject.type, eventObject);
}
}
this.bufferObject(eventObject);
}
this._events.length = 0;
}
};
DragonBones.prototype.bufferEvent = function (value) {
if (this._events.indexOf(value) < 0) {
this._events.push(value);
}
};
DragonBones.prototype.bufferObject = function (object) {
if (this._objects.indexOf(object) < 0) {
this._objects.push(object);
}
};
Object.defineProperty(DragonBones.prototype, "clock", {
get: function () {
return this._clock;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DragonBones.prototype, "eventManager", {
get: function () {
return this._eventManager;
},
enumerable: true,
configurable: true
});
DragonBones.yDown = true;
DragonBones.debug = false;
DragonBones.debugDraw = false;
DragonBones.webAssembly = false;
DragonBones.VERSION = "5.5.1";
return DragonBones;
}());
dragonBones.DragonBones = DragonBones;
if (!console.warn) {
console.warn = function () { };
}
if (!console.assert) {
console.assert = function () { };
}
})(dragonBones || (dragonBones = {}));
var dragonBones;
(function (dragonBones) {
/**
* 基础对象。
* @version DragonBones 4.5
* @language zh_CN
*/
var BaseObject = (function () {
function BaseObject() {
/**
* 对象的唯一标识。
* @version DragonBones 4.5
* @language zh_CN
*/
this.hashCode = BaseObject._hashCode++;
this._isInPool = false;
}
BaseObject._returnObject = function (object) {
var classType = String(object.constructor);
var maxCount = classType in BaseObject._maxCountMap ? BaseObject._maxCountMap[classType] : BaseObject._defaultMaxCount;
var pool = BaseObject._poolsMap[classType] = BaseObject._poolsMap[classType] || [];
if (pool.length < maxCount) {
if (!object._isInPool) {
object._isInPool = true;
pool.push(object);
}
else {
console.assert(false, "The object is already in the pool.");
}
}
else {
}
};
/**
* @private
*/
BaseObject.toString = function () {
throw new Error();
};
/**
* 设置每种对象池的最大缓存数量。
* @param objectConstructor 对象类。
* @param maxCount 最大缓存数量。 (设置为 0 则不缓存)
* @version DragonBones 4.5
* @language zh_CN
*/
BaseObject.setMaxCount = function (objectConstructor, maxCount) {
if (maxCount < 0 || maxCount !== maxCount) {
maxCount = 0;
}
if (objectConstructor !== null) {
var classType = String(objectConstructor);
var pool = classType in BaseObject._poolsMap ? BaseObject._poolsMap[classType] : null;
if (pool !== null && pool.length > maxCount) {
pool.length = maxCount;
}
BaseObject._maxCountMap[classType] = maxCount;
}
else {
BaseObject._defaultMaxCount = maxCount;
for (var classType in BaseObject._poolsMap) {
var pool = BaseObject._poolsMap[classType];
if (pool.length > maxCount) {
pool.length = maxCount;
}
if (classType in BaseObject._maxCountMap) {
BaseObject._maxCountMap[classType] = maxCount;
}
}
}
};
/**
* 清除对象池缓存的对象。
* @param objectConstructor 对象类。 (不设置则清除所有缓存)
* @version DragonBones 4.5
* @language zh_CN
*/
BaseObject.clearPool = function (objectConstructor) {
if (objectConstructor === void 0) { objectConstructor = null; }
if (objectConstructor !== null) {
var classType = String(objectConstructor);
var pool = classType in BaseObject._poolsMap ? BaseObject._poolsMap[classType] : null;
if (pool !== null && pool.length > 0) {
pool.length = 0;
}
}
else {
for (var k in BaseObject._poolsMap) {
var pool = BaseObject._poolsMap[k];
pool.length = 0;
}
}
};
/**
* 从对象池中创建指定对象。
* @param objectConstructor 对象类。
* @version DragonBones 4.5
* @language zh_CN
*/
BaseObject.borrowObject = function (objectConstructor) {
var classType = String(objectConstructor);
var pool = classType in BaseObject._poolsMap ? BaseObject._poolsMap[classType] : null;
if (pool !== null && pool.length > 0) {
var object_1 = pool.pop();
object_1._isInPool = false;
return object_1;
}
var object = new objectConstructor();
object._onClear();
return object;
};
/**
* 清除数据并返还对象池。
* @version DragonBones 4.5
* @language zh_CN
*/
BaseObject.prototype.returnToPool = function () {
this._onClear();
BaseObject._returnObject(this);
};
BaseObject._hashCode = 0;
BaseObject._defaultMaxCount = 1000;
BaseObject._maxCountMap = {};
BaseObject._poolsMap = {};
return BaseObject;
}());
dragonBones.BaseObject = BaseObject;
})(dragonBones || (dragonBones = {}));
var dragonBones;
(function (dragonBones) {
/**
* 2D 矩阵。
* @version DragonBones 3.0
* @language zh_CN
*/
var Matrix = (function () {
function Matrix(a, b, c, d, tx, ty) {
if (a === void 0) { a = 1.0; }
if (b === void 0) { b = 0.0; }
if (c === void 0) { c = 0.0; }
if (d === void 0) { d = 1.0; }
if (tx === void 0) { tx = 0.0; }
if (ty === void 0) { ty = 0.0; }
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.tx = tx;
this.ty = ty;
}
/**
* @private
*/
Matrix.prototype.toString = function () {
return "[object dragonBones.Matrix] a:" + this.a + " b:" + this.b + " c:" + this.c + " d:" + this.d + " tx:" + this.tx + " ty:" + this.ty;
};
/**
* @private
*/
Matrix.prototype.copyFrom = function (value) {
this.a = value.a;
this.b = value.b;
this.c = value.c;
this.d = value.d;
this.tx = value.tx;
this.ty = value.ty;
return this;
};
/**
* @private
*/
Matrix.prototype.copyFromArray = function (value, offset) {
if (offset === void 0) { offset = 0; }
this.a = value[offset];
this.b = value[offset + 1];
this.c = value[offset + 2];
this.d = value[offset + 3];
this.tx = value[offset + 4];
this.ty = value[offset + 5];
return this;
};
/**
* 转换为单位矩阵。
* @version DragonBones 3.0
* @language zh_CN
*/
Matrix.prototype.identity = function () {
this.a = this.d = 1.0;
this.b = this.c = 0.0;
this.tx = this.ty = 0.0;
return this;
};
/**
* 将当前矩阵与另一个矩阵相乘。
* @param value 需要相乘的矩阵。
* @version DragonBones 3.0
* @language zh_CN
*/
Matrix.prototype.concat = function (value) {
var aA = this.a * value.a;
var bA = 0.0;
var cA = 0.0;
var dA = this.d * value.d;
var txA = this.tx * value.a + value.tx;
var tyA = this.ty * value.d + value.ty;
if (this.b !== 0.0 || this.c !== 0.0) {
aA += this.b * value.c;
bA += this.b * value.d;
cA += this.c * value.a;
dA += this.c * value.b;
}
if (value.b !== 0.0 || value.c !== 0.0) {
bA += this.a * value.b;
cA += this.d * value.c;
txA += this.ty * value.c;
tyA += this.tx * value.b;
}
this.a = aA;
this.b = bA;
this.c = cA;
this.d = dA;
this.tx = txA;
this.ty = tyA;
return this;
};
/**
* 转换为逆矩阵。
* @version DragonBones 3.0
* @language zh_CN
*/
Matrix.prototype.invert = function () {
var aA = this.a;
var bA = this.b;
var cA = this.c;
var dA = this.d;
var txA = this.tx;
var tyA = this.ty;
if (bA === 0.0 && cA === 0.0) {
this.b = this.c = 0.0;
if (aA === 0.0 || dA === 0.0) {
this.a = this.b = this.tx = this.ty = 0.0;
}
else {
aA = this.a = 1.0 / aA;
dA = this.d = 1.0 / dA;
this.tx = -aA * txA;
this.ty = -dA * tyA;
}
return this;
}
var determinant = aA * dA - bA * cA;
if (determinant === 0.0) {
this.a = this.d = 1.0;
this.b = this.c = 0.0;
this.tx = this.ty = 0.0;
return this;
}
determinant = 1.0 / determinant;
var k = this.a = dA * determinant;
bA = this.b = -bA * determinant;
cA = this.c = -cA * determinant;
dA = this.d = aA * determinant;
this.tx = -(k * txA + cA * tyA);
this.ty = -(bA * txA + dA * tyA);
return this;
};
/**
* 将矩阵转换应用于指定点。
* @param x 横坐标。
* @param y 纵坐标。
* @param result 应用转换之后的坐标。
* @params delta 是否忽略 tx,ty 对坐标的转换。
* @version DragonBones 3.0
* @language zh_CN
*/
Matrix.prototype.transformPoint = function (x, y, result, delta) {
if (delta === void 0) { delta = false; }
result.x = this.a * x + this.c * y;
result.y = this.b * x + this.d * y;
if (!delta) {
result.x += this.tx;
result.y += this.ty;
}
};
/**
* @private
*/
Matrix.prototype.transformRectangle = function (rectangle, delta) {
if (delta === void 0) { delta = false; }
var a = this.a;
var b = this.b;
var c = this.c;
var d = this.d;
var tx = delta ? 0.0 : this.tx;
var ty = delta ? 0.0 : this.ty;
var x = rectangle.x;
var y = rectangle.y;
var xMax = x + rectangle.width;
var yMax = y + rectangle.height;
var x0 = a * x + c * y + tx;
var y0 = b * x + d * y + ty;
var x1 = a * xMax + c * y + tx;
var y1 = b * xMax + d * y + ty;
var x2 = a * xMax + c * yMax + tx;
var y2 = b * xMax + d * yMax + ty;
var x3 = a * x + c * yMax + tx;
var y3 = b * x + d * yMax + ty;
var tmp = 0;
if (x0 > x1) {
tmp = x0;
x0 = x1;
x1 = tmp;
}
if (x2 > x3) {
tmp = x2;
x2 = x3;
x3 = tmp;
}
rectangle.x = Math.floor(x0 < x2 ? x0 : x2);
rectangle.width = Math.ceil((x1 > x3 ? x1 : x3) - rectangle.x);
if (y0 > y1) {
tmp = y0;
y0 = y1;
y1 = tmp;
}
if (y2 > y3) {
tmp = y2;
y2 = y3;
y3 = tmp;
}
rectangle.y = Math.floor(y0 < y2 ? y0 : y2);
rectangle.height = Math.ceil((y1 > y3 ? y1 : y3) - rectangle.y);
};
return Matrix;
}());
dragonBones.Matrix = Matrix;
})(dragonBones || (dragonBones = {}));
var dragonBones;
(function (dragonBones) {
/**
* 2D 变换。
* @version DragonBones 3.0
* @language zh_CN
*/
var Transform = (function () {
function Transform(
/**
* 水平位移。
* @version DragonBones 3.0
* @language zh_CN
*/
x,
/**
* 垂直位移。
* @version DragonBones 3.0
* @language zh_CN
*/
y,
/**
* 倾斜。 (以弧度为单位)
* @version DragonBones 3.0
* @language zh_CN
*/
skew,
/**
* 旋转。 (以弧度为单位)
* @version DragonBones 3.0
* @language zh_CN
*/
rotation,
/**
* 水平缩放。
* @version DragonBones 3.0
* @language zh_CN
*/
scaleX,
/**
* 垂直缩放。
* @version DragonBones 3.0
* @language zh_CN
*/
scaleY) {
if (x === void 0) { x = 0.0; }
if (y === void 0) { y = 0.0; }
if (skew === void 0) { skew = 0.0; }
if (rotation === void 0) { rotation = 0.0; }
if (scaleX === void 0) { scaleX = 1.0; }
if (scaleY === void 0) { scaleY = 1.0; }
this.x = x;
this.y = y;
this.skew = skew;
this.rotation = rotation;
this.scaleX = scaleX;
this.scaleY = scaleY;
}
/**
* @private
*/
Transform.normalizeRadian = function (value) {
value = (value + Math.PI) % (Math.PI * 2.0);
value += value > 0.0 ? -Math.PI : Math.PI;
return value;
};
/**
* @private
*/
Transform.prototype.toString = function () {
return "[object dragonBones.Transform] x:" + this.x + " y:" + this.y + " skewX:" + this.skew * 180.0 / Math.PI + " skewY:" + this.rotation * 180.0 / Math.PI + " scaleX:" + this.scaleX + " scaleY:" + this.scaleY;
};
/**
* @private
*/
Transform.prototype.copyFrom = function (value) {
this.x = value.x;
this.y = value.y;
this.skew = value.skew;
this.rotation = value.rotation;
this.scaleX = value.scaleX;
this.scaleY = value.scaleY;
return this;
};
/**
* @private
*/
Transform.prototype.identity = function () {
this.x = this.y = 0.0;
this.skew = this.rotation = 0.0;
this.scaleX = this.scaleY = 1.0;
return this;
};
/**
* @private
*/
Transform.prototype.add = function (value) {
this.x += value.x;
this.y += value.y;
this.skew += value.skew;
this.rotation += value.rotation;
this.scaleX *= value.scaleX;
this.scaleY *= value.scaleY;
return this;
};
/**
* @private
*/
Transform.prototype.minus = function (value) {
this.x -= value.x;
this.y -= value.y;
this.skew -= value.skew;
this.rotation -= value.rotation;
this.scaleX /= value.scaleX;
this.scaleY /= value.scaleY;
return this;
};
/**
* 矩阵转换为变换。
* @param matrix 矩阵。
* @version DragonBones 3.0
* @language zh_CN
*/
Transform.prototype.fromMatrix = function (matrix) {
var backupScaleX = this.scaleX, backupScaleY = this.scaleY;
var PI_Q = Transform.PI_Q;
this.x = matrix.tx;
this.y = matrix.ty;
this.rotation = Math.atan(matrix.b / matrix.a);
var skewX = Math.atan(-matrix.c / matrix.d);
this.scaleX = (this.rotation > -PI_Q && this.rotation < PI_Q) ? matrix.a / Math.cos(this.rotation) : matrix.b / Math.sin(this.rotation);
this.scaleY = (skewX > -PI_Q && skewX < PI_Q) ? matrix.d / Math.cos(skewX) : -matrix.c / Math.sin(skewX);
if (backupScaleX >= 0.0 && this.scaleX < 0.0) {
this.scaleX = -this.scaleX;
this.rotation = this.rotation - Math.PI;
}
if (backupScaleY >= 0.0 && this.scaleY < 0.0) {
this.scaleY = -this.scaleY;
skewX = skewX - Math.PI;
}
this.skew = skewX - this.rotation;
return this;
};
/**
* 转换为矩阵。
* @param matrix 矩阵。
* @version DragonBones 3.0
* @language zh_CN
*/
Transform.prototype.toMatrix = function (matrix) {
if (this.skew !== 0.0 || this.rotation !== 0.0) {
matrix.a = Math.cos(this.rotation);
matrix.b = Math.sin(this.rotation);
if (this.skew === 0.0) {
matrix.c = -matrix.b;
matrix.d = matrix.a;
}
else {
matrix.c = -Math.sin(this.skew + this.rotation);
matrix.d = Math.cos(this.skew + this.rotation);
}
if (this.scaleX !== 1.0) {
matrix.a *= this.scaleX;
matrix.b *= this.scaleX;
}
if (this.scaleY !== 1.0) {
matrix.c *= this.scaleY;
matrix.d *= this.scaleY;
}
}
else {
matrix.a = this.scaleX;
matrix.b = 0.0;
matrix.c = 0.0;
matrix.d = this.scaleY;
}
matrix.tx = this.x;
matrix.ty = this.y;
return this;
};
/**
* @private
*/
Transform.PI_D = Math.PI * 2.0;
/**
* @private
*/
Transform.PI_H = Math.PI / 2.0;
/**
* @private
*/
Transform.PI_Q = Math.PI / 4.0;
/**
* @private
*/
Transform.RAD_DEG = 180.0 / Math.PI;
/**
* @private
*/
Transform.DEG_RAD = Math.PI / 180.0;
return Transform;
}());
dragonBones.Transform = Transform;
})(dragonBones || (dragonBones = {}));
var dragonBones;
(function (dragonBones) {
/**
* @private
*/
var ColorTransform = (function () {
function ColorTransform(alphaMultiplier, redMultiplier, greenMultiplier, blueMultiplier, alphaOffset, redOffset, greenOffset, blueOffset) {
if (alphaMultiplier === void 0) { alphaMultiplier = 1.0; }
if (redMultiplier === void 0) { redMultiplier = 1.0; }
if (greenMultiplier === void 0) { greenMultiplier = 1.0; }
if (blueMultiplier === void 0) { blueMultiplier = 1.0; }
if (alphaOffset === void 0) { alphaOffset = 0; }
if (redOffset === void 0) { redOffset = 0; }
if (greenOffset === void 0) { greenOffset = 0; }
if (blueOffset === void 0) { blueOffset = 0; }
this.alphaMultiplier = alphaMultiplier;
this.redMultiplier = redMultiplier;
this.greenMultiplier = greenMultiplier;
this.blueMultiplier = blueMultiplier;
this.alphaOffset = alphaOffset;
this.redOffset = redOffset;
this.greenOffset = greenOffset;
this.blueOffset = blueOffset;
}
ColorTransform.prototype.copyFrom = function (value) {
this.alphaMultiplier = value.alphaMultiplier;
this.redMultiplier = value.redMultiplier;
this.greenMultiplier = value.greenMultiplier;
this.blueMultiplier = value.blueMultiplier;
this.alphaOffset = value.alphaOffset;
this.redOffset = value.redOffset;
this.greenOffset = value.greenOffset;
this.blueOffset = value.blueOffset;
};
ColorTransform.prototype.identity = function () {
this.alphaMultiplier = this.redMultiplier = this.greenMultiplier = this.blueMultiplier = 1.0;
this.alphaOffset = this.redOffset = this.greenOffset = this.blueOffset = 0;
};
return ColorTransform;
}());
dragonBones.ColorTransform = ColorTransform;
})(dragonBones || (dragonBones = {}));
var dragonBones;
(function (dragonBones) {
var Point = (function () {
function Point(x, y) {
if (x === void 0) { x = 0.0; }
if (y === void 0) { y = 0.0; }
this.x = x;
this.y = y;
}
Point.prototype.copyFrom = function (value) {
this.x = value.x;
this.y = value.y;
};
Point.prototype.clear = function () {
this.x = this.y = 0.0;
};
return Point;
}());
dragonBones.Point = Point;
})(dragonBones || (dragonBones = {}));
var dragonBones;
(function (dragonBones) {
var Rectangle = (function () {
function Rectangle(x, y, width, height) {
if (x === void 0) { x = 0.0; }
if (y === void 0) { y = 0.0; }
if (width === void 0) { width = 0.0; }
if (height === void 0) { height = 0.0; }
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
Rectangle.prototype.copyFrom = function (value) {
this.x = value.x;
this.y = value.y;
this.width = value.width;
this.height = value.height;
};
Rectangle.prototype.clear = function () {
this.x = this.y = 0.0;
this.width = this.height = 0.0;
};
return Rectangle;
}());
dragonBones.Rectangle = Rectangle;
})(dragonBones || (dragonBones = {}));
var dragonBones;
(function (dragonBones) {
/**
* 自定义数据。
* @version DragonBones 5.0
* @language zh_CN
*/
var UserData = (function (_super) {
__extends(UserData, _super);
function UserData() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* 自定义整数。
* @version DragonBones 5.0
* @language zh_CN
*/
_this.ints = [];
/**
* 自定义浮点数。
* @version DragonBones 5.0
* @language zh_CN
*/
_this.floats = [];
/**
* 自定义字符串。
* @version DragonBones 5.0
* @language zh_CN
*/
_this.strings = [];
return _this;
}
/**
* @private
*/
UserData.toString = function () {
return "[class dragonBones.UserData]";
};
/**
* @private
*/
UserData.prototype._onClear = function () {
this.ints.length = 0;
this.floats.length = 0;
this.strings.length = 0;
};
/**
* @private
*/
UserData.prototype.addInt = function (value) {
this.ints.push(value);
};
/**
* @private
*/
UserData.prototype.addFloat = function (value) {
this.floats.push(value);
};
/**
* @private
*/
UserData.prototype.addString = function (value) {
this.strings.push(value);
};
/**
* 获取自定义整数。
* @version DragonBones 5.0
* @language zh_CN
*/
UserData.prototype.getInt = function (index) {
if (index === void 0) { index = 0; }
return index >= 0 && index < this.ints.length ? this.ints[index] : 0;
};
/**
* 获取自定义浮点数。
* @version DragonBones 5.0
* @language zh_CN
*/
UserData.prototype.getFloat = function (index) {
if (index === void 0) { index = 0; }
return index >= 0 && index < this.floats.length ? this.floats[index] : 0.0;
};
/**
* 获取自定义字符串。
* @version DragonBones 5.0
* @language zh_CN
*/
UserData.prototype.getString = function (index) {
if (index === void 0) { index = 0; }
return index >= 0 && index < this.strings.length ? this.strings[index] : "";
};
return UserData;
}(dragonBones.BaseObject));
dragonBones.UserData = UserData;
/**
* @private
*/
var ActionData = (function (_super) {
__extends(ActionData, _super);
function ActionData() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.data = null; //
return _this;
}
ActionData.toString = function () {
return "[class dragonBones.ActionData]";
};
ActionData.prototype._onClear = function () {
if (this.data !== null) {
this.data.returnToPool();
}
this.type = 0 /* Play */;
this.name = "";
this.bone = null;
this.slot = null;
this.data = null;
};
return ActionData;
}(dragonBones.BaseObject));
dragonBones.ActionData = ActionData;
})(dragonBones || (dragonBones = {}));
var dragonBones;
(function (dragonBones) {
/**
* 龙骨数据。
* 一个龙骨数据包含多个骨架数据。
* @see dragonBones.ArmatureData
* @version DragonBones 3.0
* @language zh_CN
*/
var DragonBonesData = (function (_super) {
__extends(DragonBonesData, _super);
function DragonBonesData() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @private
*/
_this.frameIndices = [];
/**
* @private
*/
_this.cachedFrames = [];
/**
* 所有骨架数据名称。
* @see #armatures
* @version DragonBones 3.0
* @language zh_CN
*/
_this.armatureNames = [];
/**
* 所有骨架数据。
* @see dragonBones.ArmatureData
* @version DragonBones 3.0
* @language zh_CN
*/
_this.armatures = {};
/**
* @private
*/
_this.userData = null; // Initial value.
return _this;
}
/**
* @private
*/
DragonBonesData.toString = function () {
return "[class dragonBones.DragonBonesData]";
};
/**
* @private
*/
DragonBonesData.prototype._onClear = function () {
for (var k in this.armatures) {
this.armatures[k].returnToPool();
delete this.armatures[k];
}
if (this.userData !== null) {
this.userData.returnToPool();
}
this.autoSearch = false;
this.frameRate = 0;
this.version = "";
this.name = "";
this.stage = null;
this.frameIndices.length = 0;
this.cachedFrames.length = 0;
this.armatureNames.length = 0;
//this.armatures.clear();
this.binary = null; //
this.intArray = null; //
this.floatArray = null; //
this.frameIntArray = null; //
this.frameFloatArray = null; //
this.frameArray = null; //
this.timelineArray = null; //
this.userData = null;
};
/**
* @private
*/
DragonBonesData.prototype.addArmature = function (value) {
if (value.name in this.armatures) {
console.warn("Replace armature: " + value.name);
this.armatures[value.name].returnToPool();
}
value.parent = this;
this.armatures[value.name] = value;
this.armatureNames.push(value.name);
};
/**
* 获取骨架数据。
* @param name 骨架数据名称。
* @see dragonBones.ArmatureData
* @version DragonBones 3.0
* @language zh_CN
*/
DragonBonesData.prototype.getArmature = function (name) {
return name in this.armatures ? this.armatures[name] : null;
};
/**
* @deprecated
* 已废弃,请参考 @see
* @see dragonBones.BaseFactory#removeDragonBonesData()
*/
DragonBonesData.prototype.dispose = function () {
console.warn("已废弃,请参考 @see");
this.returnToPool();
};
return DragonBonesData;
}(dragonBones.BaseObject));
dragonBones.DragonBonesData = DragonBonesData;
})(dragonBones || (dragonBones = {}));
var dragonBones;
(function (dragonBones) {
/**
* @private
*/
var CanvasData = (function (_super) {
__extends(CanvasData, _super);
function CanvasData() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* @private
*/
CanvasData.toString = function () {
return "[class dragonBones.CanvasData]";
};
/**
* @private
*/
CanvasData.prototype._onClear = function () {
this.hasBackground = false;
this.color = 0x000000;
this.x = 0;
this.y = 0;
this.width = 0;
this.height = 0;
};
return CanvasData;
}(dragonBones.BaseObject));
dragonBones.CanvasData = CanvasData;
/**
* 骨架数据。
* @version DragonBones 3.0
* @language zh_CN
*/
var ArmatureData = (function (_super) {
__extends(ArmatureData, _super);
function ArmatureData() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @private
*/
_this.aabb = new dragonBones.Rectangle();
/**
* 所有动画数据名称。
* @see #armatures
* @version DragonBones 3.0
* @language zh_CN
*/
_this.animationNames = [];
/**
* @private
*/
_this.sortedBones = [];
/**
* @private
*/
_this.sortedSlots = [];
/**
* @private
*/
_this.defaultActions = [];
/**
* @private
*/
_this.actions = [];
/**
* 所有骨骼数据。
* @see dragonBones.BoneData
* @version DragonBones 3.0
* @language zh_CN
*/
_this.bones = {};
/**
* 所有插槽数据。
* @see dragonBones.SlotData
* @version DragonBones 3.0
* @language zh_CN
*/
_this.slots = {};
/**
* 所有皮肤数据。
* @see dragonBones.SkinData
* @version DragonBones 3.0
* @language zh_CN
*/
_this.skins = {};
/**
* 所有动画数据。
* @see dragonBones.AnimationData
* @version DragonBones 3.0
* @language zh_CN
*/
_this.animations = {};
/**
* @private
*/
_this.canvas = null; // Initial value.
/**
* @private
*/
_this.userData = null; // Initial value.
return _this;
}
/**
* @private
*/
ArmatureData.toString = function () {
return "[class dragonBones.ArmatureData]";
};
/**
* @private
*/
ArmatureData.prototype._onClear = function () {
for (var _i = 0, _a = this.defaultActions; _i < _a.length; _i++) {
var action = _a[_i];
action.returnToPool();
}
for (var _b = 0, _c = this.actions; _b < _c.length; _b++) {
var action = _c[_b];
action.returnToPool();
}
for (var k in this.bones) {
this.bones[k].returnToPool();
delete this.bones[k];
}
for (var k in this.slots) {
this.slots[k].returnToPool();
delete this.slots[k];
}
for (var k in this.skins) {
this.skins[k].returnToPool();
delete this.skins[k];
}
for (var k in this.animations) {
this.animations[k].returnToPool();
delete this.animations[k];
}
if (this.canvas !== null) {
this.canvas.returnToPool();
}
if (this.userData !== null) {
this.userData.returnToPool();
}
this.type = 0 /* Armature */;
this.frameRate = 0;
this.cacheFrameRate = 0;
this.scale = 1.0;
this.name = "";
this.aabb.clear();
this.animationNames.length = 0;
this.sortedBones.length = 0;
this.sortedSlots.length = 0;
this.defaultActions.length = 0;
this.actions.length = 0;
//this.bones.clear();
//this.slots.clear();
//this.skins.clear();
//this.animations.clear();
this.defaultSkin = null;
this.defaultAnimation = null;
this.canvas = null;
this.userData = null;
this.parent = null; //
};
/**
* @private
*/
ArmatureData.prototype.sortBones = function () {
var total = this.sortedBones.length;
if (total <= 0) {
return;
}
var sortHelper = this.sortedBones.concat();
var index = 0;
var count = 0;
this.sortedBones.length = 0;
while (count < total) {
var bone = sortHelper[index++];
if (index >= total) {
index = 0;
}
if (this.sortedBones.indexOf(bone) >= 0) {
continue;
}
if (bone.constraints.length > 0) {
var flag = false;
for (var _i = 0, _a = bone.constraints; _i < _a.length; _i++) {
var constraint = _a[_i];
if (this.sortedBones.indexOf(constraint.target) < 0) {
flag = true;
}
}
if (flag) {
continue;
}
}
if (bone.parent !== null && this.sortedBones.indexOf(bone.parent) < 0) {
continue;
}
this.sortedBones.push(bone);
count++;
}
};
/**
* @private
*/
ArmatureData.prototype.cacheFrames = function (frameRate) {
if (this.cacheFrameRate > 0) {
return;
}
this.cacheFrameRate = frameRate;
for (var k in this.animations) {
this.animations[k].cacheFrames(this.cacheFrameRate);
}
};
/**
* @private
*/
ArmatureData.prototype.setCacheFrame = function (globalTransformMatrix, transform) {
var dataArray = this.parent.cachedFrames;
var arrayOffset = dataArray.length;
dataArray.length += 10;
dataArray[arrayOffset] = globalTransformMatrix.a;
dataArray[arrayOffset + 1] = globalTransformMatrix.b;
dataArray[arrayOffset + 2] = globalTransformMatrix.c;
dataArray[arrayOffset + 3] = globalTransformMatrix.d;
dataArray[arrayOffset + 4] = globalTransformMatrix.tx;
dataArray[arrayOffset + 5] = globalTransformMatrix.ty;
dataArray[arrayOffset + 6] = transform.rotation;
dataArray[arrayOffset + 7] = transform.skew;
dataArray[arrayOffset + 8] = transform.scaleX;
dataArray[arrayOffset + 9] = transform.scaleY;
return arrayOffset;
};
/**
* @private
*/
ArmatureData.prototype.getCacheFrame = function (globalTransformMatrix, transform, arrayOffset) {
var dataArray = this.parent.cachedFrames;
globalTransformMatrix.a = dataArray[arrayOffset];
globalTransformMatrix.b = dataArray[arrayOffset + 1];
globalTransformMatrix.c = dataArray[arrayOffset + 2];
globalTransformMatrix.d = dataArray[arrayOffset + 3];
globalTransformMatrix.tx = dataArray[arrayOffset + 4];
globalTransformMatrix.ty = dataArray[arrayOffset + 5];
transform.rotation = dataArray[arrayOffset + 6];
transform.skew = dataArray[arrayOffset + 7];
transform.scaleX = dataArray[arrayOffset + 8];
transform.scaleY = dataArray[arrayOffset + 9];
transform.x = globalTransformMatrix.tx;
transform.y = globalTransformMatrix.ty;
};
/**
* @private
*/
ArmatureData.prototype.addBone = function (value) {
if (value.name in this.bones) {
console.warn("Replace bone: " + value.name);
this.bones[value.name].returnToPool();
}
this.bones[value.name] = value;
this.sortedBones.push(value);
};
/**
* @private
*/
ArmatureData.prototype.addSlot = function (value) {
if (value.name in this.slots) {
console.warn("Replace slot: " + value.name);
this.slots[value.name].returnToPool();
}
this.slots[value.name] = value;
this.sortedSlots.push(value);
};
/**
* @private
*/
ArmatureData.prototype.addSkin = function (value) {
if (value.name in this.skins) {
console.warn("Replace skin: " + value.name);
this.skins[value.name].returnToPool();
}
value.parent = this;
this.skins[value.name] = value;
if (this.defaultSkin === null) {
this.defaultSkin = value;
}
};
/**
* @private
*/
ArmatureData.prototype.addAnimation = function (value) {
if (value.name in this.animations) {
console.warn("Replace animation: " + value.name);
this.animations[value.name].returnToPool();
}
value.parent = this;
this.animations[value.name] = value;
this.animationNames.push(value.name);
if (this.defaultAnimation === null) {
this.defaultAnimation = value;
}
};
/**
* @private
*/
ArmatureData.prototype.addAction = function (value, isDefault) {
if (isDefault) {
this.defaultActions.push(value);
}
else {
this.actions.push(value);
}
};
/**
* 获取骨骼数据。
* @param name 数据名称。
* @version DragonBones 3.0
* @see dragonBones.BoneData
* @language zh_CN
*/
ArmatureData.prototype.getBone = function (name) {
return name in this.bones ? this.bones[name] : null;
};
/**
* 获取插槽数据。
* @param name 数据名称。
* @version DragonBones 3.0
* @see dragonBones.SlotData
* @language zh_CN
*/
ArmatureData.prototype.getSlot = function (name) {
return name in this.slots ? this.slots[name] : null;
};
/**
* 获取皮肤数据。
* @param name 数据名称。
* @version DragonBones 3.0
* @see dragonBones.SkinData
* @language zh_CN
*/
ArmatureData.prototype.getSkin = function (name) {
return name in this.skins ? this.skins[name] : null;
};
/**
* 获取动画数据。
* @param name 数据名称。
* @version DragonBones 3.0
* @see dragonBones.AnimationData
* @language zh_CN
*/
ArmatureData.prototype.getAnimation = function (name) {
return name in this.animations ? this.animations[name] : null;
};
return ArmatureData;
}(dragonBones.BaseObject));
dragonBones.ArmatureData = ArmatureData;
/**
* 骨骼数据。
* @version DragonBones 3.0
* @language zh_CN
*/
var BoneData = (function (_super) {
__extends(BoneData, _super);
function BoneData() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @private
*/
_this.transform = new dragonBones.Transform();
/**
* @private
*/
_this.constraints = [];
/**
* @private
*/
_this.userData = null; // Initial value.
return _this;
}
/**
* @private
*/
BoneData.toString = function () {
return "[class dragonBones.BoneData]";
};
/**
* @private
*/
BoneData.prototype._onClear = function () {
for (var _i = 0, _a = this.constraints; _i < _a.length; _i++) {
var constraint = _a[_i];
constraint.returnToPool();
}
if (this.userData !== null) {
this.userData.returnToPool();
}
this.inheritTranslation = false;
this.inheritRotation = false;
this.inheritScale = false;
this.inheritReflection = false;
this.length = 0.0;
this.name = "";
this.transform.identity();
this.constraints.length = 0;
this.userData = null;
this.parent = null;
};
/**
* @private
*/
BoneData.prototype.addConstraint = function (value) {
this.constraints.push(value);
};
return BoneData;
}(dragonBones.BaseObject));
dragonBones.BoneData = BoneData;
/**
* 插槽数据。
* @see dragonBones.Slot
* @version DragonBones 3.0
* @language zh_CN
*/
var SlotData = (function (_super) {
__extends(SlotData, _super);
function SlotData() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @private
*/
_this.color = null; // Initial value.
/**
* @private
*/
_this.userData = null; // Initial value.
return _this;
}
/**
* @private
*/
SlotData.createColor = function () {
return new dragonBones.ColorTransform();
};
/**
* @private
*/
SlotData.toString = function () {
return "[class dragonBones.SlotData]";
};
/**
* @private
*/
SlotData.prototype._onClear = function () {
if (this.userData !== null) {
this.userData.returnToPool();
}
this.blendMode = 0 /* Normal */;
this.displayIndex = 0;
this.zOrder = 0;
this.name = "";
this.color = null; //
this.userData = null;
this.parent = null; //
};
/**
* @private
*/
SlotData.DEFAULT_COLOR = new dragonBones.ColorTransform();
return SlotData;
}(dragonBones.BaseObject));
dragonBones.SlotData = SlotData;
/**
* 皮肤数据。(通常一个骨架数据至少包含一个皮肤数据)
* @version DragonBones 3.0
* @language zh_CN
*/
var SkinData = (function (_super) {
__extends(SkinData, _super);
function SkinData() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @private
*/
_this.displays = {};
return _this;
}
SkinData.toString = function () {
return "[class dragonBones.SkinData]";
};
/**
* @private
*/
SkinData.prototype._onClear = function () {
for (var k in this.displays) {
var slotDisplays = this.displays[k];
for (var _i = 0, slotDisplays_1 = slotDisplays; _i < slotDisplays_1.length; _i++) {
var display = slotDisplays_1[_i];
if (display !== null) {
display.returnToPool();
}
}
delete this.displays[k];
}
this.name = "";
// this.displays.clear();
this.parent = null; //
};
/**
* @private
*/
SkinData.prototype.addDisplay = function (slotName, value) {
if (!(slotName in this.displays)) {
this.displays[slotName] = [];