[ts] Ported skin API changes, see #841.

This commit is contained in:
badlogic 2019-05-10 15:07:06 +02:00
parent b71970afa6
commit 576c1da32f
14 changed files with 11388 additions and 10947 deletions

View File

@ -87,6 +87,7 @@ public class PathAttachment extends VertexAttachment {
System.arraycopy(lengths, 0, copy.lengths, 0, lengths.length); System.arraycopy(lengths, 0, copy.lengths, 0, lengths.length);
copy.closed = closed; copy.closed = closed;
copy.constantSpeed = constantSpeed; copy.constantSpeed = constantSpeed;
copy.color.set(color);
return copy; return copy;
} }
} }

View File

@ -771,12 +771,26 @@ declare module spine {
} }
} }
declare module spine { declare module spine {
class SkinEntry {
slotIndex: number;
name: string;
attachment: Attachment;
constructor(slotIndex: number, name: string, attachment: Attachment);
}
class Skin { class Skin {
name: string; name: string;
attachments: Map<Attachment>[]; attachments: Map<Attachment>[];
bones: BoneData[];
constraints: SlotData[];
constructor(name: string); constructor(name: string);
addAttachment(slotIndex: number, name: string, attachment: Attachment): void; setAttachment(slotIndex: number, name: string, attachment: Attachment): void;
addSkin(skin: Skin): void;
copySkin(skin: Skin): void;
getAttachment(slotIndex: number, name: string): Attachment; getAttachment(slotIndex: number, name: string): Attachment;
removeAttachment(slotIndex: number, name: string): void;
getAttachments(): Array<SkinEntry>;
getAttachmentsForSlot(slotIndex: number, attachments: Array<SkinEntry>): void;
clear(): void;
attachAll(skeleton: Skeleton, oldSkin: Skin): void; attachAll(skeleton: Skeleton, oldSkin: Skin): void;
} }
} }
@ -1081,6 +1095,7 @@ declare module spine {
abstract class Attachment { abstract class Attachment {
name: string; name: string;
constructor(name: string); constructor(name: string);
abstract copy(): Attachment;
} }
abstract class VertexAttachment extends Attachment { abstract class VertexAttachment extends Attachment {
private static nextID; private static nextID;
@ -1091,6 +1106,7 @@ declare module spine {
constructor(name: string); constructor(name: string);
computeWorldVertices(slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number, stride: number): void; computeWorldVertices(slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number, stride: number): void;
applyDeform(sourceAttachment: VertexAttachment): boolean; applyDeform(sourceAttachment: VertexAttachment): boolean;
copyTo(attachment: VertexAttachment): void;
} }
} }
declare module spine { declare module spine {
@ -1117,6 +1133,7 @@ declare module spine {
class BoundingBoxAttachment extends VertexAttachment { class BoundingBoxAttachment extends VertexAttachment {
color: Color; color: Color;
constructor(name: string); constructor(name: string);
copy(): Attachment;
} }
} }
declare module spine { declare module spine {
@ -1124,6 +1141,7 @@ declare module spine {
endSlot: SlotData; endSlot: SlotData;
color: Color; color: Color;
constructor(name: string); constructor(name: string);
copy(): Attachment;
} }
} }
declare module spine { declare module spine {
@ -1134,7 +1152,10 @@ declare module spine {
uvs: ArrayLike<number>; uvs: ArrayLike<number>;
triangles: Array<number>; triangles: Array<number>;
color: Color; color: Color;
width: number;
height: number;
hullLength: number; hullLength: number;
edges: Array<number>;
private parentMesh; private parentMesh;
inheritDeform: boolean; inheritDeform: boolean;
tempColor: Color; tempColor: Color;
@ -1143,6 +1164,7 @@ declare module spine {
applyDeform(sourceAttachment: VertexAttachment): boolean; applyDeform(sourceAttachment: VertexAttachment): boolean;
getParentMesh(): MeshAttachment; getParentMesh(): MeshAttachment;
setParentMesh(parentMesh: MeshAttachment): void; setParentMesh(parentMesh: MeshAttachment): void;
copy(): Attachment;
} }
} }
declare module spine { declare module spine {
@ -1152,6 +1174,7 @@ declare module spine {
constantSpeed: boolean; constantSpeed: boolean;
color: Color; color: Color;
constructor(name: string); constructor(name: string);
copy(): Attachment;
} }
} }
declare module spine { declare module spine {
@ -1163,6 +1186,7 @@ declare module spine {
constructor(name: string); constructor(name: string);
computeWorldPosition(bone: Bone, point: Vector2): Vector2; computeWorldPosition(bone: Bone, point: Vector2): Vector2;
computeWorldRotation(bone: Bone): number; computeWorldRotation(bone: Bone): number;
copy(): Attachment;
} }
} }
declare module spine { declare module spine {
@ -1225,6 +1249,7 @@ declare module spine {
updateOffset(): void; updateOffset(): void;
setRegion(region: TextureRegion): void; setRegion(region: TextureRegion): void;
computeWorldVertices(bone: Bone, worldVertices: ArrayLike<number>, offset: number, stride: number): void; computeWorldVertices(bone: Bone, worldVertices: ArrayLike<number>, offset: number, stride: number): void;
copy(): Attachment;
} }
} }
declare module spine { declare module spine {

View File

@ -4675,7 +4675,7 @@ var spine;
for (var entryName in slotMap) { for (var entryName in slotMap) {
var attachment = this.readAttachment(slotMap[entryName], skin, slotIndex, entryName, skeletonData); var attachment = this.readAttachment(slotMap[entryName], skin, slotIndex, entryName, skeletonData);
if (attachment != null) if (attachment != null)
skin.addAttachment(slotIndex, entryName, attachment); skin.setAttachment(slotIndex, entryName, attachment);
} }
} }
skeletonData.skins.push(skin); skeletonData.skins.push(skin);
@ -4762,6 +4762,8 @@ var spine;
var color = this.getValue(map, "color", null); var color = this.getValue(map, "color", null);
if (color != null) if (color != null)
mesh.color.setFromString(color); mesh.color.setFromString(color);
mesh.width = this.getValue(map, "width", 0) * scale;
mesh.height = this.getValue(map, "height", 0) * scale;
var parent_4 = this.getValue(map, "parent", null); var parent_4 = this.getValue(map, "parent", null);
if (parent_4 != null) { if (parent_4 != null) {
mesh.inheritDeform = this.getValue(map, "deform", true); mesh.inheritDeform = this.getValue(map, "deform", true);
@ -4773,6 +4775,7 @@ var spine;
mesh.triangles = map.triangles; mesh.triangles = map.triangles;
mesh.regionUVs = uvs; mesh.regionUVs = uvs;
mesh.updateUVs(); mesh.updateUVs();
mesh.edges = this.getValue(map, "edges", null);
mesh.hullLength = this.getValue(map, "hull", 0) * 2; mesh.hullLength = this.getValue(map, "hull", 0) * 2;
return mesh; return mesh;
} }
@ -5241,14 +5244,25 @@ var spine;
})(spine || (spine = {})); })(spine || (spine = {}));
var spine; var spine;
(function (spine) { (function (spine) {
var SkinEntry = (function () {
function SkinEntry(slotIndex, name, attachment) {
this.slotIndex = slotIndex;
this.name = name;
this.attachment = attachment;
}
return SkinEntry;
}());
spine.SkinEntry = SkinEntry;
var Skin = (function () { var Skin = (function () {
function Skin(name) { function Skin(name) {
this.attachments = new Array(); this.attachments = new Array();
this.bones = Array();
this.constraints = new Array();
if (name == null) if (name == null)
throw new Error("name cannot be null."); throw new Error("name cannot be null.");
this.name = name; this.name = name;
} }
Skin.prototype.addAttachment = function (slotIndex, name, attachment) { Skin.prototype.setAttachment = function (slotIndex, name, attachment) {
if (attachment == null) if (attachment == null)
throw new Error("attachment cannot be null."); throw new Error("attachment cannot be null.");
var attachments = this.attachments; var attachments = this.attachments;
@ -5258,10 +5272,118 @@ var spine;
attachments[slotIndex] = {}; attachments[slotIndex] = {};
attachments[slotIndex][name] = attachment; attachments[slotIndex][name] = attachment;
}; };
Skin.prototype.addSkin = function (skin) {
for (var i = 0; i < skin.bones.length; i++) {
var bone = skin.bones[i];
var contained = false;
for (var j = 0; j < this.bones.length; j++) {
if (this.bones[j] == bone) {
contained = true;
break;
}
}
if (!contained)
this.bones.push(bone);
}
for (var i = 0; i < skin.constraints.length; i++) {
var constraint = skin.constraints[i];
var contained = false;
for (var j = 0; j < this.constraints.length; j++) {
if (this.constraints[j] == constraint) {
contained = true;
break;
}
}
if (!contained)
this.constraints.push(constraint);
}
var attachments = skin.getAttachments();
for (var i = 0; i < attachments.length; i++) {
var attachment = attachments[i];
this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
}
};
Skin.prototype.copySkin = function (skin) {
for (var i = 0; i < skin.bones.length; i++) {
var bone = skin.bones[i];
var contained = false;
for (var j = 0; j < this.bones.length; j++) {
if (this.bones[j] == bone) {
contained = true;
break;
}
}
if (!contained)
this.bones.push(bone);
}
for (var i = 0; i < skin.constraints.length; i++) {
var constraint = skin.constraints[i];
var contained = false;
for (var j = 0; j < this.constraints.length; j++) {
if (this.constraints[j] == constraint) {
contained = true;
break;
}
}
if (!contained)
this.constraints.push(constraint);
}
var attachments = skin.getAttachments();
for (var i = 0; i < attachments.length; i++) {
var attachment = attachments[i];
attachment.attachment = attachment.attachment.copy();
this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
}
attachments = this.getAttachments();
for (var i = 0; i < attachments.length; i++) {
var attachment_1 = attachments[i];
if (attachment_1.attachment instanceof spine.MeshAttachment) {
var mesh = attachment_1.attachment;
if (mesh.getParentMesh()) {
mesh.setParentMesh(this.getAttachment(attachment_1.slotIndex, mesh.getParentMesh().name));
mesh.updateUVs();
}
}
}
};
Skin.prototype.getAttachment = function (slotIndex, name) { Skin.prototype.getAttachment = function (slotIndex, name) {
var dictionary = this.attachments[slotIndex]; var dictionary = this.attachments[slotIndex];
return dictionary ? dictionary[name] : null; return dictionary ? dictionary[name] : null;
}; };
Skin.prototype.removeAttachment = function (slotIndex, name) {
var dictionary = this.attachments[slotIndex];
if (dictionary)
dictionary[name] = null;
};
Skin.prototype.getAttachments = function () {
var entries = new Array();
for (var i = 0; i < this.attachments.length; i++) {
var slotAttachments = this.attachments[i];
if (slotAttachments) {
for (var name_2 in slotAttachments) {
var attachment = slotAttachments[name_2];
if (attachment)
entries.push(new SkinEntry(i, name_2, attachment));
}
}
}
return entries;
};
Skin.prototype.getAttachmentsForSlot = function (slotIndex, attachments) {
var slotAttachments = this.attachments[slotIndex];
if (slotAttachments) {
for (var name_3 in slotAttachments) {
var attachment = slotAttachments[name_3];
if (attachment)
attachments.push(new SkinEntry(slotIndex, name_3, attachment));
}
}
};
Skin.prototype.clear = function () {
this.attachments.length = 0;
this.bones.length = 0;
this.constraints.length = 0;
};
Skin.prototype.attachAll = function (skeleton, oldSkin) { Skin.prototype.attachAll = function (skeleton, oldSkin) {
var slotIndex = 0; var slotIndex = 0;
for (var i = 0; i < skeleton.slots.length; i++) { for (var i = 0; i < skeleton.slots.length; i++) {
@ -6533,6 +6655,21 @@ var spine;
VertexAttachment.prototype.applyDeform = function (sourceAttachment) { VertexAttachment.prototype.applyDeform = function (sourceAttachment) {
return this == sourceAttachment; return this == sourceAttachment;
}; };
VertexAttachment.prototype.copyTo = function (attachment) {
if (this.bones != null) {
attachment.bones = new Array(this.bones.length);
spine.Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
}
else
attachment.bones = null;
if (this.vertices != null) {
attachment.vertices = spine.Utils.newFloatArray(this.vertices.length);
spine.Utils.arrayCopy(this.vertices, 0, attachment.vertices, 0, this.vertices.length);
}
else
attachment.vertices = null;
attachment.worldVerticesLength = this.worldVerticesLength;
};
VertexAttachment.nextID = 0; VertexAttachment.nextID = 0;
return VertexAttachment; return VertexAttachment;
}(Attachment)); }(Attachment));
@ -6559,6 +6696,12 @@ var spine;
_this.color = new spine.Color(1, 1, 1, 1); _this.color = new spine.Color(1, 1, 1, 1);
return _this; return _this;
} }
BoundingBoxAttachment.prototype.copy = function () {
var copy = new BoundingBoxAttachment(name);
this.copyTo(copy);
copy.color.setFromColor(this.color);
return copy;
};
return BoundingBoxAttachment; return BoundingBoxAttachment;
}(spine.VertexAttachment)); }(spine.VertexAttachment));
spine.BoundingBoxAttachment = BoundingBoxAttachment; spine.BoundingBoxAttachment = BoundingBoxAttachment;
@ -6572,6 +6715,13 @@ var spine;
_this.color = new spine.Color(0.2275, 0.2275, 0.8078, 1); _this.color = new spine.Color(0.2275, 0.2275, 0.8078, 1);
return _this; return _this;
} }
ClippingAttachment.prototype.copy = function () {
var copy = new ClippingAttachment(name);
this.copyTo(copy);
copy.endSlot = this.endSlot;
copy.color.setFromColor(this.color);
return copy;
};
return ClippingAttachment; return ClippingAttachment;
}(spine.VertexAttachment)); }(spine.VertexAttachment));
spine.ClippingAttachment = ClippingAttachment; spine.ClippingAttachment = ClippingAttachment;
@ -6665,6 +6815,34 @@ var spine;
this.worldVerticesLength = parentMesh.worldVerticesLength; this.worldVerticesLength = parentMesh.worldVerticesLength;
} }
}; };
MeshAttachment.prototype.copy = function () {
var copy = new MeshAttachment(name);
copy.region = this.region;
copy.path = this.path;
if (this.parentMesh == null) {
this.copyTo(copy);
copy.regionUVs = new Array(this.regionUVs.length);
spine.Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
copy.uvs = new Array(this.uvs.length);
spine.Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
copy.triangles = new Array(this.triangles.length);
spine.Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
copy.color.setFromColor(this.color);
copy.hullLength = this.hullLength;
copy.inheritDeform = this.inheritDeform;
if (this.edges != null) {
copy.edges = new Array(this.edges.length);
spine.Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
}
copy.width = this.width;
copy.height = this.height;
}
else {
copy.setParentMesh(this.parentMesh);
copy.updateUVs();
}
return copy;
};
return MeshAttachment; return MeshAttachment;
}(spine.VertexAttachment)); }(spine.VertexAttachment));
spine.MeshAttachment = MeshAttachment; spine.MeshAttachment = MeshAttachment;
@ -6680,6 +6858,16 @@ var spine;
_this.color = new spine.Color(1, 1, 1, 1); _this.color = new spine.Color(1, 1, 1, 1);
return _this; return _this;
} }
PathAttachment.prototype.copy = function () {
var copy = new PathAttachment(name);
this.copyTo(copy);
copy.lengths = new Array(this.lengths.length);
spine.Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
copy.closed = closed;
copy.constantSpeed = this.constantSpeed;
copy.color.setFromColor(this.color);
return copy;
};
return PathAttachment; return PathAttachment;
}(spine.VertexAttachment)); }(spine.VertexAttachment));
spine.PathAttachment = PathAttachment; spine.PathAttachment = PathAttachment;
@ -6704,6 +6892,14 @@ var spine;
var y = cos * bone.c + sin * bone.d; var y = cos * bone.c + sin * bone.d;
return Math.atan2(y, x) * spine.MathUtils.radDeg; return Math.atan2(y, x) * spine.MathUtils.radDeg;
}; };
PointAttachment.prototype.copy = function () {
var copy = new PointAttachment(name);
copy.x = this.x;
copy.y = this.y;
copy.rotation = this.rotation;
copy.color.setFromColor(this.color);
return copy;
};
return PointAttachment; return PointAttachment;
}(spine.VertexAttachment)); }(spine.VertexAttachment));
spine.PointAttachment = PointAttachment; spine.PointAttachment = PointAttachment;
@ -6804,6 +7000,23 @@ var spine;
worldVertices[offset] = offsetX * a + offsetY * b + x; worldVertices[offset] = offsetX * a + offsetY * b + x;
worldVertices[offset + 1] = offsetX * c + offsetY * d + y; worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
}; };
RegionAttachment.prototype.copy = function () {
var copy = new RegionAttachment(name);
copy.region = this.region;
copy.rendererObject = this.rendererObject;
copy.path = this.path;
copy.x = this.x;
copy.y = this.y;
copy.scaleX = this.scaleX;
copy.scaleY = this.scaleY;
copy.rotation = this.rotation;
copy.width = this.width;
copy.height = this.height;
spine.Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, 8);
spine.Utils.arrayCopy(this.offset, 0, copy.offset, 0, 8);
copy.color.setFromColor(this.color);
return copy;
};
RegionAttachment.OX1 = 0; RegionAttachment.OX1 = 0;
RegionAttachment.OY1 = 1; RegionAttachment.OY1 = 1;
RegionAttachment.OX2 = 2; RegionAttachment.OX2 = 2;

File diff suppressed because one or more lines are too long

View File

@ -214,7 +214,7 @@ module spine {
let slotMap = skinMap[slotName]; let slotMap = skinMap[slotName];
for (let entryName in slotMap) { for (let entryName in slotMap) {
let attachment = this.readAttachment(slotMap[entryName], skin, slotIndex, entryName, skeletonData); let attachment = this.readAttachment(slotMap[entryName], skin, slotIndex, entryName, skeletonData);
if (attachment != null) skin.addAttachment(slotIndex, entryName, attachment); if (attachment != null) skin.setAttachment(slotIndex, entryName, attachment);
} }
} }
skeletonData.skins.push(skin); skeletonData.skins.push(skin);
@ -306,6 +306,9 @@ module spine {
let color = this.getValue(map, "color", null); let color = this.getValue(map, "color", null);
if (color != null) mesh.color.setFromString(color); if (color != null) mesh.color.setFromString(color);
mesh.width = this.getValue(map, "width", 0) * scale;
mesh.height = this.getValue(map, "height", 0) * scale;
let parent: string = this.getValue(map, "parent", null); let parent: string = this.getValue(map, "parent", null);
if (parent != null) { if (parent != null) {
mesh.inheritDeform = this.getValue(map, "deform", true); mesh.inheritDeform = this.getValue(map, "deform", true);
@ -319,6 +322,7 @@ module spine {
mesh.regionUVs = uvs; mesh.regionUVs = uvs;
mesh.updateUVs(); mesh.updateUVs();
mesh.edges = this.getValue(map, "edges", null);
mesh.hullLength = this.getValue(map, "hull", 0) * 2; mesh.hullLength = this.getValue(map, "hull", 0) * 2;
return mesh; return mesh;
} }

View File

@ -28,16 +28,22 @@
*****************************************************************************/ *****************************************************************************/
module spine { module spine {
export class SkinEntry {
constructor(public slotIndex: number, public name: string, public attachment: Attachment) { }
}
export class Skin { export class Skin {
name: string; name: string;
attachments = new Array<Map<Attachment>>(); attachments = new Array<Map<Attachment>>();
bones = Array<BoneData>();
constraints = new Array<SlotData>();
constructor (name: string) { constructor (name: string) {
if (name == null) throw new Error("name cannot be null."); if (name == null) throw new Error("name cannot be null.");
this.name = name; this.name = name;
} }
addAttachment (slotIndex: number, name: string, attachment: Attachment) { setAttachment (slotIndex: number, name: string, attachment: Attachment) {
if (attachment == null) throw new Error("attachment cannot be null."); if (attachment == null) throw new Error("attachment cannot be null.");
let attachments = this.attachments; let attachments = this.attachments;
if (slotIndex >= attachments.length) attachments.length = slotIndex + 1; if (slotIndex >= attachments.length) attachments.length = slotIndex + 1;
@ -45,12 +51,124 @@ module spine {
attachments[slotIndex][name] = attachment; attachments[slotIndex][name] = attachment;
} }
addSkin (skin: Skin) {
for(let i = 0; i < skin.bones.length; i++) {
let bone = skin.bones[i];
let contained = false;
for (let j = 0; j < this.bones.length; j++) {
if (this.bones[j] == bone) {
contained = true;
break;
}
}
if (!contained) this.bones.push(bone);
}
for(let i = 0; i < skin.constraints.length; i++) {
let constraint = skin.constraints[i];
let contained = false;
for (let j = 0; j < this.constraints.length; j++) {
if (this.constraints[j] == constraint) {
contained = true;
break;
}
}
if (!contained) this.constraints.push(constraint);
}
let attachments = skin.getAttachments();
for (let i = 0; i < attachments.length; i++) {
var attachment = attachments[i];
this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
}
}
copySkin (skin: Skin) {
for(let i = 0; i < skin.bones.length; i++) {
let bone = skin.bones[i];
let contained = false;
for (let j = 0; j < this.bones.length; j++) {
if (this.bones[j] == bone) {
contained = true;
break;
}
}
if (!contained) this.bones.push(bone);
}
for(let i = 0; i < skin.constraints.length; i++) {
let constraint = skin.constraints[i];
let contained = false;
for (let j = 0; j < this.constraints.length; j++) {
if (this.constraints[j] == constraint) {
contained = true;
break;
}
}
if (!contained) this.constraints.push(constraint);
}
let attachments = skin.getAttachments();
for (let i = 0; i < attachments.length; i++) {
var attachment = attachments[i];
attachment.attachment = attachment.attachment.copy();
this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
}
attachments = this.getAttachments();
for (let i = 0; i < attachments.length; i++) {
let attachment = attachments[i];
if (attachment.attachment instanceof MeshAttachment) {
let mesh = attachment.attachment as MeshAttachment;
if (mesh.getParentMesh()) {
mesh.setParentMesh(this.getAttachment(attachment.slotIndex, mesh.getParentMesh().name) as MeshAttachment);
mesh.updateUVs();
}
}
}
}
/** @return May be null. */ /** @return May be null. */
getAttachment (slotIndex: number, name: string): Attachment { getAttachment (slotIndex: number, name: string): Attachment {
let dictionary = this.attachments[slotIndex]; let dictionary = this.attachments[slotIndex];
return dictionary ? dictionary[name] : null; return dictionary ? dictionary[name] : null;
} }
removeAttachment (slotIndex: number, name: string) {
let dictionary = this.attachments[slotIndex];
if (dictionary) dictionary[name] = null;
}
getAttachments (): Array<SkinEntry> {
let entries = new Array<SkinEntry>();
for (var i = 0; i < this.attachments.length; i++) {
let slotAttachments = this.attachments[i];
if (slotAttachments) {
for (let name in slotAttachments) {
let attachment = slotAttachments[name];
if (attachment) entries.push(new SkinEntry(i, name, attachment));
}
}
}
return entries;
}
getAttachmentsForSlot (slotIndex: number, attachments: Array<SkinEntry>) {
let slotAttachments = this.attachments[slotIndex];
if (slotAttachments) {
for (let name in slotAttachments) {
let attachment = slotAttachments[name];
if (attachment) attachments.push(new SkinEntry(slotIndex, name, attachment));
}
}
}
clear () {
this.attachments.length = 0;
this.bones.length = 0;
this.constraints.length = 0;
}
/** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */ /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */
attachAll (skeleton: Skeleton, oldSkin: Skin) { attachAll (skeleton: Skeleton, oldSkin: Skin) {
let slotIndex = 0; let slotIndex = 0;

View File

@ -35,6 +35,8 @@ module spine {
if (name == null) throw new Error("name cannot be null."); if (name == null) throw new Error("name cannot be null.");
this.name = name; this.name = name;
} }
abstract copy (): Attachment;
} }
export abstract class VertexAttachment extends Attachment { export abstract class VertexAttachment extends Attachment {
@ -116,5 +118,21 @@ module spine {
applyDeform (sourceAttachment: VertexAttachment) { applyDeform (sourceAttachment: VertexAttachment) {
return this == sourceAttachment; return this == sourceAttachment;
} }
copyTo (attachment: VertexAttachment) {
if (this.bones != null) {
attachment.bones = new Array<number>(this.bones.length);
Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
} else
attachment.bones = null;
if (this.vertices != null) {
attachment.vertices = Utils.newFloatArray(this.vertices.length);
Utils.arrayCopy(this.vertices, 0, attachment.vertices, 0, this.vertices.length);
} else
attachment.vertices = null;
attachment.worldVerticesLength = this.worldVerticesLength;
}
} }
} }

View File

@ -34,5 +34,12 @@ module spine {
constructor (name: string) { constructor (name: string) {
super(name); super(name);
} }
copy (): Attachment {
let copy = new BoundingBoxAttachment(name);
this.copyTo(copy);
copy.color.setFromColor(this.color);
return copy;
}
} }
} }

View File

@ -37,5 +37,13 @@ module spine {
constructor (name: string) { constructor (name: string) {
super(name); super(name);
} }
copy (): Attachment {
let copy = new ClippingAttachment(name);
this.copyTo(copy);
copy.endSlot = this.endSlot;
copy.color.setFromColor(this.color);
return copy;
}
} }
} }

View File

@ -34,7 +34,10 @@ module spine {
regionUVs: ArrayLike<number>; uvs: ArrayLike<number>; regionUVs: ArrayLike<number>; uvs: ArrayLike<number>;
triangles: Array<number>; triangles: Array<number>;
color = new Color(1, 1, 1, 1); color = new Color(1, 1, 1, 1);
width: number;
height: number;
hullLength: number; hullLength: number;
edges: Array<number>;
private parentMesh: MeshAttachment; private parentMesh: MeshAttachment;
inheritDeform = false; inheritDeform = false;
tempColor = new Color(0, 0, 0, 0); tempColor = new Color(0, 0, 0, 0);
@ -102,33 +105,6 @@ module spine {
} }
} }
/*updateUVs () {
let u = 0, v = 0, width = 0, height = 0;
if (this.region == null) {
u = v = 0;
width = height = 1;
} else {
u = this.region.u;
v = this.region.v;
width = this.region.u2 - u;
height = this.region.v2 - v;
}
let regionUVs = this.regionUVs;
if (this.uvs == null || this.uvs.length != regionUVs.length) this.uvs = Utils.newFloatArray(regionUVs.length);
let uvs = this.uvs;
if (this.region.rotate) {
for (let i = 0, n = uvs.length; i < n; i += 2) {
uvs[i] = u + regionUVs[i + 1] * width;
uvs[i + 1] = v + height - regionUVs[i] * height;
}
} else {
for (let i = 0, n = uvs.length; i < n; i += 2) {
uvs[i] = u + regionUVs[i] * width;
uvs[i + 1] = v + regionUVs[i + 1] * height;
}
}
}*/
applyDeform (sourceAttachment: VertexAttachment): boolean { applyDeform (sourceAttachment: VertexAttachment): boolean {
return this == sourceAttachment || (this.inheritDeform && this.parentMesh == sourceAttachment); return this == sourceAttachment || (this.inheritDeform && this.parentMesh == sourceAttachment);
} }
@ -150,6 +126,39 @@ module spine {
this.worldVerticesLength = parentMesh.worldVerticesLength this.worldVerticesLength = parentMesh.worldVerticesLength
} }
} }
copy (): Attachment {
let copy = new MeshAttachment(name);
copy.region = this.region;
copy.path = this.path;
if (this.parentMesh == null) {
this.copyTo(copy);
copy.regionUVs = new Array<number>(this.regionUVs.length);
Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
copy.uvs = new Array<number>(this.uvs.length);
Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
copy.triangles = new Array<number>(this.triangles.length);
Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
copy.color.setFromColor(this.color);
copy.hullLength = this.hullLength;
copy.inheritDeform = this.inheritDeform;
// Nonessential.
if (this.edges != null) {
copy.edges = new Array<number>(this.edges.length);
Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
}
copy.width = this.width;
copy.height = this.height;
} else {
copy.setParentMesh(this.parentMesh);
copy.updateUVs();
}
return copy;
}
} }
} }

View File

@ -36,5 +36,16 @@ module spine {
constructor (name: string) { constructor (name: string) {
super(name); super(name);
} }
copy (): Attachment {
let copy = new PathAttachment(name);
this.copyTo(copy);
copy.lengths = new Array<number>(this.lengths.length);
Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
copy.closed = closed;
copy.constantSpeed = this.constantSpeed;
copy.color.setFromColor(this.color);
return copy;
}
} }
} }

View File

@ -48,5 +48,14 @@ module spine {
let y = cos * bone.c + sin * bone.d; let y = cos * bone.c + sin * bone.d;
return Math.atan2(y, x) * MathUtils.radDeg; return Math.atan2(y, x) * MathUtils.radDeg;
} }
copy (): Attachment {
let copy = new PointAttachment(name);
copy.x = this.x;
copy.y = this.y;
copy.rotation = this.rotation;
copy.color.setFromColor(this.color);
return copy;
}
} }
} }

View File

@ -172,5 +172,23 @@ module spine {
worldVertices[offset] = offsetX * a + offsetY * b + x; // ur worldVertices[offset] = offsetX * a + offsetY * b + x; // ur
worldVertices[offset + 1] = offsetX * c + offsetY * d + y; worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
} }
copy (): Attachment {
let copy = new RegionAttachment(name);
copy.region = this.region;
copy.rendererObject = this.rendererObject;
copy.path = this.path;
copy.x = this.x;
copy.y = this.y;
copy.scaleX = this.scaleX;
copy.scaleY = this.scaleY;
copy.rotation = this.rotation;
copy.width = this.width;
copy.height = this.height;
Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, 8);
Utils.arrayCopy(this.offset, 0, copy.offset, 0, 8);
copy.color.setFromColor(this.color);
return copy;
}
} }
} }

View File

@ -164,7 +164,7 @@ var skinsDemo = function(canvas, bgColor) {
var skin = skins[(Math.random() * skins.length - 1) | 0]; var skin = skins[(Math.random() * skins.length - 1) | 0];
var attachments = skin.attachments[slot]; var attachments = skin.attachments[slot];
for (var attachmentName in attachments) { for (var attachmentName in attachments) {
newSkin.addAttachment(slot, attachmentName, attachments[attachmentName]); newSkin.setAttachment(slot, attachmentName, attachments[attachmentName]);
} }
} }
setSkin(newSkin); setSkin(newSkin);