mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
[as3] Fixed all warnings. Improved color parsing.
This commit is contained in:
parent
ec164cf479
commit
7dc954f943
@ -30,7 +30,7 @@
|
|||||||
package spine {
|
package spine {
|
||||||
import flash.utils.ByteArray;
|
import flash.utils.ByteArray;
|
||||||
|
|
||||||
class BinaryInput {
|
internal class BinaryInput {
|
||||||
private var bytes : ByteArray;
|
private var bytes : ByteArray;
|
||||||
public var strings : Vector.<String> = new Vector.<String>();
|
public var strings : Vector.<String> = new Vector.<String>();
|
||||||
|
|
||||||
|
|||||||
@ -64,6 +64,7 @@ package spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setFromString(hex : String) : Color {
|
public function setFromString(hex : String) : Color {
|
||||||
|
if (hex.length != 8 && hex.length != 6) throw new ArgumentError("Hexadecimal color length must be 6 or 8: " + hex);
|
||||||
hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
|
hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
|
||||||
this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
|
this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
|
||||||
this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
|
this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
|
||||||
@ -108,5 +109,9 @@ package spine {
|
|||||||
g = ((value & 0x0000ff00) >>> 8) / 255;
|
g = ((value & 0x0000ff00) >>> 8) / 255;
|
||||||
b = ((value & 0x000000ff)) / 255;
|
b = ((value & 0x000000ff)) / 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function fromString (hex : String) : Color {
|
||||||
|
return new Color(0, 0, 0, 0).setFromString(hex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -126,9 +126,9 @@ package spine {
|
|||||||
}
|
}
|
||||||
var b : Number = bone.data.length * sx, dd : Number = Math.sqrt(tx * tx + ty * ty);
|
var b : Number = bone.data.length * sx, dd : Number = Math.sqrt(tx * tx + ty * ty);
|
||||||
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
||||||
var s : Number = (dd / b - 1) * alpha + 1;
|
var ss : Number = (dd / b - 1) * alpha + 1;
|
||||||
sx *= s;
|
sx *= ss;
|
||||||
if (uniform) sy *= s;
|
if (uniform) sy *= ss;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bone.updateWorldTransformWith(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, sx, sy, bone.ashearX, bone.ashearY);
|
bone.updateWorldTransformWith(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, sx, sy, bone.ashearX, bone.ashearY);
|
||||||
|
|||||||
@ -511,7 +511,7 @@ package spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function toString() : String {
|
public function toString() : String {
|
||||||
return _data.name != null ? _data.name : super.toString();
|
return _data.name == null ? "null" : _data.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBounds(offset : Vector.<Number>, size : Vector.<Number>, temp : Vector.<Number>) : void {
|
public function getBounds(offset : Vector.<Number>, size : Vector.<Number>, temp : Vector.<Number>) : void {
|
||||||
|
|||||||
@ -166,7 +166,7 @@ package spine {
|
|||||||
|
|
||||||
// ---
|
// ---
|
||||||
public function toString() : String {
|
public function toString() : String {
|
||||||
return name != null ? name : super.toString();
|
return name == null ? "null" : name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -96,8 +96,6 @@ package spine {
|
|||||||
if (skeletonMap) {
|
if (skeletonMap) {
|
||||||
skeletonData.hash = skeletonMap["hash"];
|
skeletonData.hash = skeletonMap["hash"];
|
||||||
skeletonData.version = skeletonMap["spine"];
|
skeletonData.version = skeletonMap["spine"];
|
||||||
if ("3.8.75" == skeletonData.version)
|
|
||||||
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
|
||||||
skeletonData.x = skeletonMap["x"] || 0;
|
skeletonData.x = skeletonMap["x"] || 0;
|
||||||
skeletonData.y = skeletonMap["y"] || 0;
|
skeletonData.y = skeletonMap["y"] || 0;
|
||||||
skeletonData.width = skeletonMap["width"] || 0;
|
skeletonData.width = skeletonMap["width"] || 0;
|
||||||
@ -126,6 +124,10 @@ package spine {
|
|||||||
boneData.shearY = Number(boneMap["shearY"] || 0);
|
boneData.shearY = Number(boneMap["shearY"] || 0);
|
||||||
boneData.transformMode = TransformMode[boneMap["transform"] || "normal"];
|
boneData.transformMode = TransformMode[boneMap["transform"] || "normal"];
|
||||||
boneData.skinRequired = boneMap.hasOwnProperty("skin") ? boneMap["skin"] : false;
|
boneData.skinRequired = boneMap.hasOwnProperty("skin") ? boneMap["skin"] : false;
|
||||||
|
|
||||||
|
color = boneMap["color"];
|
||||||
|
if (color) boneData.color.setFromString(color);
|
||||||
|
|
||||||
skeletonData.bones.push(boneData);
|
skeletonData.bones.push(boneData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,14 +140,10 @@ package spine {
|
|||||||
var slotData : SlotData = new SlotData(skeletonData.slots.length, slotName, boneData);
|
var slotData : SlotData = new SlotData(skeletonData.slots.length, slotName, boneData);
|
||||||
|
|
||||||
var color : String = slotMap["color"];
|
var color : String = slotMap["color"];
|
||||||
if (color) {
|
if (color) slotData.color.setFromString(color);
|
||||||
slotData.color.setFrom(toColor(color, 0), toColor(color, 1), toColor(color, 2), toColor(color, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
var dark : String = slotMap["dark"];
|
var dark : String = slotMap["dark"];
|
||||||
if (dark) {
|
if (dark) slotData.darkColor = Color.fromString(dark);
|
||||||
slotData.darkColor = new Color(toColor(dark, 0), toColor(dark, 1), toColor(dark, 2), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
slotData.attachmentName = slotMap["attachment"];
|
slotData.attachmentName = slotMap["attachment"];
|
||||||
slotData.blendMode = BlendMode[slotMap["blend"] || "normal"];
|
slotData.blendMode = BlendMode[slotMap["blend"] || "normal"];
|
||||||
@ -248,15 +246,16 @@ package spine {
|
|||||||
|
|
||||||
if (skinMap["bones"]) {
|
if (skinMap["bones"]) {
|
||||||
for (ii = 0; ii < skinMap["bones"].length; ii++) {
|
for (ii = 0; ii < skinMap["bones"].length; ii++) {
|
||||||
var boneData : BoneData = skeletonData.findBone(skinMap["bones"][ii]);
|
boneData = skeletonData.findBone(skinMap["bones"][ii]);
|
||||||
if (boneData == null) throw new Error("Skin bone not found: " + skinMap["bones"][ii]);
|
if (boneData == null) throw new Error("Skin bone not found: " + skinMap["bones"][ii]);
|
||||||
skin.bones.push(boneData);
|
skin.bones.push(boneData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var constraint : ConstraintData;
|
||||||
if (skinMap["ik"]) {
|
if (skinMap["ik"]) {
|
||||||
for (ii = 0; ii < skinMap["ik"].length; ii++) {
|
for (ii = 0; ii < skinMap["ik"].length; ii++) {
|
||||||
var constraint : ConstraintData = skeletonData.findIkConstraint(skinMap["ik"][ii]);
|
constraint = skeletonData.findIkConstraint(skinMap["ik"][ii]);
|
||||||
if (constraint == null) throw new Error("Skin IK constraint not found: " + skinMap["ik"][ii]);
|
if (constraint == null) throw new Error("Skin IK constraint not found: " + skinMap["ik"][ii]);
|
||||||
skin.constraints.push(constraint);
|
skin.constraints.push(constraint);
|
||||||
}
|
}
|
||||||
@ -264,7 +263,7 @@ package spine {
|
|||||||
|
|
||||||
if (skinMap["transform"]) {
|
if (skinMap["transform"]) {
|
||||||
for (ii = 0; ii < skinMap["transform"].length; ii++) {
|
for (ii = 0; ii < skinMap["transform"].length; ii++) {
|
||||||
var constraint : ConstraintData = skeletonData.findTransformConstraint(skinMap["transform"][ii]);
|
constraint = skeletonData.findTransformConstraint(skinMap["transform"][ii]);
|
||||||
if (constraint == null) throw new Error("Skin transform constraint not found: " + skinMap["transform"][ii]);
|
if (constraint == null) throw new Error("Skin transform constraint not found: " + skinMap["transform"][ii]);
|
||||||
skin.constraints.push(constraint);
|
skin.constraints.push(constraint);
|
||||||
}
|
}
|
||||||
@ -272,7 +271,7 @@ package spine {
|
|||||||
|
|
||||||
if (skinMap["path"]) {
|
if (skinMap["path"]) {
|
||||||
for (ii = 0; ii < skinMap["path"].length; ii++) {
|
for (ii = 0; ii < skinMap["path"].length; ii++) {
|
||||||
var constraint : ConstraintData = skeletonData.findPathConstraint(skinMap["path"][ii]);
|
constraint = skeletonData.findPathConstraint(skinMap["path"][ii]);
|
||||||
if (constraint == null) throw new Error("Skin path constraint not found: " + skinMap["path"][ii]);
|
if (constraint == null) throw new Error("Skin path constraint not found: " + skinMap["path"][ii]);
|
||||||
skin.constraints.push(constraint);
|
skin.constraints.push(constraint);
|
||||||
}
|
}
|
||||||
@ -351,10 +350,10 @@ package spine {
|
|||||||
region.rotation = map["rotation"] || 0;
|
region.rotation = map["rotation"] || 0;
|
||||||
region.width = Number(map["width"] || 0) * scale;
|
region.width = Number(map["width"] || 0) * scale;
|
||||||
region.height = Number(map["height"] || 0) * scale;
|
region.height = Number(map["height"] || 0) * scale;
|
||||||
|
|
||||||
color = map["color"];
|
color = map["color"];
|
||||||
if (color) {
|
if (color) region.color.setFromString(color);
|
||||||
region.color.setFrom(toColor(color, 0), toColor(color, 1), toColor(color, 2), toColor(color, 3));
|
|
||||||
}
|
|
||||||
region.updateOffset();
|
region.updateOffset();
|
||||||
return region;
|
return region;
|
||||||
case AttachmentType.mesh:
|
case AttachmentType.mesh:
|
||||||
@ -362,10 +361,10 @@ package spine {
|
|||||||
var mesh : MeshAttachment = attachmentLoader.newMeshAttachment(skin, name, map["path"] || name);
|
var mesh : MeshAttachment = attachmentLoader.newMeshAttachment(skin, name, map["path"] || name);
|
||||||
if (!mesh) return null;
|
if (!mesh) return null;
|
||||||
mesh.path = map["path"] || name;
|
mesh.path = map["path"] || name;
|
||||||
|
|
||||||
color = map["color"];
|
color = map["color"];
|
||||||
if (color) {
|
if (color) mesh.color.setFromString(color);
|
||||||
mesh.color.setFrom(toColor(color, 0), toColor(color, 1), toColor(color, 2), toColor(color, 3));
|
|
||||||
}
|
|
||||||
mesh.width = Number(map["width"] || 0) * scale;
|
mesh.width = Number(map["width"] || 0) * scale;
|
||||||
mesh.height = Number(map["height"] || 0) * scale;
|
mesh.height = Number(map["height"] || 0) * scale;
|
||||||
if (map["parent"]) {
|
if (map["parent"]) {
|
||||||
@ -405,10 +404,10 @@ package spine {
|
|||||||
point.x = map.hasOwnProperty("x") ? Number(map["x"]) * scale : 0;
|
point.x = map.hasOwnProperty("x") ? Number(map["x"]) * scale : 0;
|
||||||
point.y = map.hasOwnProperty("y") ? Number(map["y"]) * scale : 0;
|
point.y = map.hasOwnProperty("y") ? Number(map["y"]) * scale : 0;
|
||||||
point.rotation = map.hasOwnProperty("rotation") ? Number(map["rotation"]) : 0;
|
point.rotation = map.hasOwnProperty("rotation") ? Number(map["rotation"]) : 0;
|
||||||
|
|
||||||
color = map["color"];
|
color = map["color"];
|
||||||
if (color) {
|
if (color) point.color.setFromString(color);
|
||||||
point.color.setFrom(toColor(color, 0), toColor(color, 1), toColor(color, 2), toColor(color, 3));
|
|
||||||
}
|
|
||||||
return point;
|
return point;
|
||||||
case AttachmentType.clipping:
|
case AttachmentType.clipping:
|
||||||
var clip : ClippingAttachment = attachmentLoader.newClippingAttachment(skin, name);
|
var clip : ClippingAttachment = attachmentLoader.newClippingAttachment(skin, name);
|
||||||
@ -422,10 +421,10 @@ package spine {
|
|||||||
|
|
||||||
vertexCount = int(map["vertexCount"]);
|
vertexCount = int(map["vertexCount"]);
|
||||||
readVertices(map, clip, vertexCount << 1);
|
readVertices(map, clip, vertexCount << 1);
|
||||||
|
|
||||||
color = map["color"];
|
color = map["color"];
|
||||||
if (color) {
|
if (color) clip.color.setFromString(color);
|
||||||
clip.color.setFrom(toColor(color, 0), toColor(color, 1), toColor(color, 2), toColor(color, 3));
|
|
||||||
}
|
|
||||||
return clip;
|
return clip;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,12 +494,8 @@ package spine {
|
|||||||
|
|
||||||
frameIndex = 0;
|
frameIndex = 0;
|
||||||
for each (valueMap in values) {
|
for each (valueMap in values) {
|
||||||
var color : String = valueMap["color"];
|
var frameColor : Color = Color.fromString(valueMap["color"]);
|
||||||
var r : Number = toColor(color, 0);
|
colorTimeline.setFrame(frameIndex, Number(valueMap["time"] || 0), frameColor.r, frameColor.g, frameColor.b, frameColor.a);
|
||||||
var g : Number = toColor(color, 1);
|
|
||||||
var b : Number = toColor(color, 2);
|
|
||||||
var a : Number = toColor(color, 3);
|
|
||||||
colorTimeline.setFrame(frameIndex, Number(valueMap["time"] || 0), r, g, b, a);
|
|
||||||
readCurve(valueMap, colorTimeline, frameIndex);
|
readCurve(valueMap, colorTimeline, frameIndex);
|
||||||
frameIndex++;
|
frameIndex++;
|
||||||
}
|
}
|
||||||
@ -512,12 +507,10 @@ package spine {
|
|||||||
|
|
||||||
frameIndex = 0;
|
frameIndex = 0;
|
||||||
for each (valueMap in values) {
|
for each (valueMap in values) {
|
||||||
color = valueMap["light"];
|
var color : String = valueMap["light"];
|
||||||
var darkColor : String = valueMap["dark"];
|
var darkColor : String = valueMap["dark"];
|
||||||
var light : Color = new Color(0, 0, 0, 0);
|
var light : Color = Color.fromString(color);
|
||||||
var dark : Color = new Color(0, 0, 0, 0);
|
var dark : Color = Color.fromString(darkColor);
|
||||||
light.setFrom(toColor(color, 0), toColor(color, 1), toColor(color, 2), toColor(color, 3));
|
|
||||||
dark.setFrom(toColor(darkColor, 0), toColor(darkColor, 1), toColor(darkColor, 2), toColor(darkColor, 3));
|
|
||||||
twoColorTimeline.setFrame(frameIndex, Number(valueMap["time"] || 0), light.r, light.g, light.b, light.a, dark.r, dark.g, dark.b);
|
twoColorTimeline.setFrame(frameIndex, Number(valueMap["time"] || 0), light.r, light.g, light.b, light.a, dark.r, dark.g, dark.b);
|
||||||
readCurve(valueMap, twoColorTimeline, frameIndex);
|
readCurve(valueMap, twoColorTimeline, frameIndex);
|
||||||
frameIndex++;
|
frameIndex++;
|
||||||
@ -797,11 +790,6 @@ package spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static private function toColor(hexString : String, colorIndex : int) : Number {
|
|
||||||
if (hexString.length != 8 && hexString.length != 6) throw new ArgumentError("Color hexidecimal length must be 6 or 8, received: " + hexString);
|
|
||||||
return parseInt(hexString.substring(colorIndex * 2, colorIndex * 2 + 2), 16) / 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
static private function getFloatArray(map : Object, name : String, scale : Number) : Vector.<Number> {
|
static private function getFloatArray(map : Object, name : String, scale : Number) : Vector.<Number> {
|
||||||
var list : Array = map[name];
|
var list : Array = map[name];
|
||||||
var values : Vector.<Number> = new Vector.<Number>(list.length, true);
|
var values : Vector.<Number> = new Vector.<Number>(list.length, true);
|
||||||
|
|||||||
@ -182,9 +182,10 @@ package spine.animation {
|
|||||||
var timelineCount : int = current.animation.timelines.length;
|
var timelineCount : int = current.animation.timelines.length;
|
||||||
var timelines : Vector.<Timeline> = current.animation.timelines;
|
var timelines : Vector.<Timeline> = current.animation.timelines;
|
||||||
var ii : int = 0;
|
var ii : int = 0;
|
||||||
|
var timeline : Timeline;
|
||||||
if ((i == 0 && mix == 1) || blend == MixBlend.add) {
|
if ((i == 0 && mix == 1) || blend == MixBlend.add) {
|
||||||
for (ii = 0; ii < timelineCount; ii++) {
|
for (ii = 0; ii < timelineCount; ii++) {
|
||||||
var timeline : Timeline = timelines[ii];
|
timeline = timelines[ii];
|
||||||
if (timeline is AttachmentTimeline) {
|
if (timeline is AttachmentTimeline) {
|
||||||
applyAttachmentTimeline(AttachmentTimeline(timeline), skeleton, animationTime, blend, true);
|
applyAttachmentTimeline(AttachmentTimeline(timeline), skeleton, animationTime, blend, true);
|
||||||
} else {
|
} else {
|
||||||
@ -199,7 +200,7 @@ package spine.animation {
|
|||||||
var timelinesRotation : Vector.<Number> = current.timelinesRotation;
|
var timelinesRotation : Vector.<Number> = current.timelinesRotation;
|
||||||
|
|
||||||
for (ii = 0; ii < timelineCount; ii++) {
|
for (ii = 0; ii < timelineCount; ii++) {
|
||||||
var timeline : Timeline = timelines[ii];
|
timeline = timelines[ii];
|
||||||
var timelineBlend : MixBlend = timelineMode[ii] == SUBSEQUENT ? blend : MixBlend.setup;
|
var timelineBlend : MixBlend = timelineMode[ii] == SUBSEQUENT ? blend : MixBlend.setup;
|
||||||
if (timeline is RotateTimeline) {
|
if (timeline is RotateTimeline) {
|
||||||
applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
|
applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
|
||||||
@ -220,8 +221,8 @@ package spine.animation {
|
|||||||
// the time is before the first key).
|
// the time is before the first key).
|
||||||
var setupState : int = unkeyedState + SETUP;
|
var setupState : int = unkeyedState + SETUP;
|
||||||
var slots : Vector.<Slot> = skeleton.slots;
|
var slots : Vector.<Slot> = skeleton.slots;
|
||||||
for (var i : int = 0, n : int = skeleton.slots.length; i < n; i++) {
|
for (var si : int = 0, sn : int = skeleton.slots.length; si < sn; si++) {
|
||||||
var slot : Slot = slots[i];
|
var slot : Slot = slots[si];
|
||||||
if (slot.attachmentState == setupState) {
|
if (slot.attachmentState == setupState) {
|
||||||
var attachmentName : String = slot.data.attachmentName;
|
var attachmentName : String = slot.data.attachmentName;
|
||||||
slot.attachment = (attachmentName == null ? null : skeleton.getAttachmentForSlotIndex(slot.data.index, attachmentName));
|
slot.attachment = (attachmentName == null ? null : skeleton.getAttachmentForSlotIndex(slot.data.index, attachmentName));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user