|
@@ -109,27 +109,30 @@ namespace Spine {
|
|
|
}
|
|
|
|
|
|
// Bones.
|
|
|
- foreach (Dictionary<string, Object> boneMap in (List<Object>)root["bones"]) {
|
|
|
- BoneData parent = null;
|
|
|
- if (boneMap.ContainsKey("parent")) {
|
|
|
- parent = skeletonData.FindBone((string)boneMap["parent"]);
|
|
|
- if (parent == null)
|
|
|
- throw new Exception("Parent bone not found: " + boneMap["parent"]);
|
|
|
+ if (root.ContainsKey("bones")) {
|
|
|
+ foreach (Dictionary<string, Object> boneMap in (List<Object>)root["bones"]) {
|
|
|
+ BoneData parent = null;
|
|
|
+ if (boneMap.ContainsKey("parent")) {
|
|
|
+ parent = skeletonData.FindBone((string)boneMap["parent"]);
|
|
|
+ if (parent == null)
|
|
|
+ throw new Exception("Parent bone not found: " + boneMap["parent"]);
|
|
|
+ }
|
|
|
+ var data = new BoneData(skeletonData.Bones.Count, (string)boneMap["name"], parent);
|
|
|
+ data.length = GetFloat(boneMap, "length", 0) * scale;
|
|
|
+ data.x = GetFloat(boneMap, "x", 0) * scale;
|
|
|
+ data.y = GetFloat(boneMap, "y", 0) * scale;
|
|
|
+ data.rotation = GetFloat(boneMap, "rotation", 0);
|
|
|
+ data.scaleX = GetFloat(boneMap, "scaleX", 1);
|
|
|
+ data.scaleY = GetFloat(boneMap, "scaleY", 1);
|
|
|
+ data.shearX = GetFloat(boneMap, "shearX", 0);
|
|
|
+ data.shearY = GetFloat(boneMap, "shearY", 0);
|
|
|
+
|
|
|
+ string tm = GetString(boneMap, "transform", TransformMode.Normal.ToString());
|
|
|
+ data.transformMode = (TransformMode)Enum.Parse(typeof(TransformMode), tm, true);
|
|
|
+ data.skinRequired = GetBoolean(boneMap, "skin", false);
|
|
|
+
|
|
|
+ skeletonData.bones.Add(data);
|
|
|
}
|
|
|
- var data = new BoneData(skeletonData.Bones.Count, (string)boneMap["name"], parent);
|
|
|
- data.length = GetFloat(boneMap, "length", 0) * scale;
|
|
|
- data.x = GetFloat(boneMap, "x", 0) * scale;
|
|
|
- data.y = GetFloat(boneMap, "y", 0) * scale;
|
|
|
- data.rotation = GetFloat(boneMap, "rotation", 0);
|
|
|
- data.scaleX = GetFloat(boneMap, "scaleX", 1);
|
|
|
- data.scaleY = GetFloat(boneMap, "scaleY", 1);
|
|
|
- data.shearX = GetFloat(boneMap, "shearX", 0);
|
|
|
- data.shearY = GetFloat(boneMap, "shearY", 0);
|
|
|
-
|
|
|
- string tm = GetString(boneMap, "transform", TransformMode.Normal.ToString());
|
|
|
- data.transformMode = (TransformMode)Enum.Parse(typeof(TransformMode), tm, true);
|
|
|
-
|
|
|
- skeletonData.bones.Add(data);
|
|
|
}
|
|
|
|
|
|
// Slots.
|
|
@@ -171,16 +174,19 @@ namespace Spine {
|
|
|
foreach (Dictionary<string, Object> constraintMap in (List<Object>)root["ik"]) {
|
|
|
IkConstraintData data = new IkConstraintData((string)constraintMap["name"]);
|
|
|
data.order = GetInt(constraintMap, "order", 0);
|
|
|
+ data.skinRequired = GetBoolean(constraintMap,"skin", false);
|
|
|
|
|
|
- foreach (string boneName in (List<Object>)constraintMap["bones"]) {
|
|
|
- BoneData bone = skeletonData.FindBone(boneName);
|
|
|
- if (bone == null) throw new Exception("IK constraint bone not found: " + boneName);
|
|
|
- data.bones.Add(bone);
|
|
|
+ if (constraintMap.ContainsKey("bones")) {
|
|
|
+ foreach (string boneName in (List<Object>)constraintMap["bones"]) {
|
|
|
+ BoneData bone = skeletonData.FindBone(boneName);
|
|
|
+ if (bone == null) throw new Exception("IK bone not found: " + boneName);
|
|
|
+ data.bones.Add(bone);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
string targetName = (string)constraintMap["target"];
|
|
|
data.target = skeletonData.FindBone(targetName);
|
|
|
- if (data.target == null) throw new Exception("Target bone not found: " + targetName);
|
|
|
+ if (data.target == null) throw new Exception("IK target bone not found: " + targetName);
|
|
|
data.mix = GetFloat(constraintMap, "mix", 1);
|
|
|
data.bendDirection = GetBoolean(constraintMap, "bendPositive", true) ? 1 : -1;
|
|
|
data.compress = GetBoolean(constraintMap, "compress", false);
|
|
@@ -196,16 +202,19 @@ namespace Spine {
|
|
|
foreach (Dictionary<string, Object> constraintMap in (List<Object>)root["transform"]) {
|
|
|
TransformConstraintData data = new TransformConstraintData((string)constraintMap["name"]);
|
|
|
data.order = GetInt(constraintMap, "order", 0);
|
|
|
+ data.skinRequired = GetBoolean(constraintMap,"skin", false);
|
|
|
|
|
|
- foreach (string boneName in (List<Object>)constraintMap["bones"]) {
|
|
|
- BoneData bone = skeletonData.FindBone(boneName);
|
|
|
- if (bone == null) throw new Exception("Transform constraint bone not found: " + boneName);
|
|
|
- data.bones.Add(bone);
|
|
|
+ if (constraintMap.ContainsKey("bones")) {
|
|
|
+ foreach (string boneName in (List<Object>)constraintMap["bones"]) {
|
|
|
+ BoneData bone = skeletonData.FindBone(boneName);
|
|
|
+ if (bone == null) throw new Exception("Transform constraint bone not found: " + boneName);
|
|
|
+ data.bones.Add(bone);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
string targetName = (string)constraintMap["target"];
|
|
|
data.target = skeletonData.FindBone(targetName);
|
|
|
- if (data.target == null) throw new Exception("Target bone not found: " + targetName);
|
|
|
+ if (data.target == null) throw new Exception("Transform constraint target bone not found: " + targetName);
|
|
|
|
|
|
data.local = GetBoolean(constraintMap, "local", false);
|
|
|
data.relative = GetBoolean(constraintMap, "relative", false);
|
|
@@ -231,16 +240,19 @@ namespace Spine {
|
|
|
foreach (Dictionary<string, Object> constraintMap in (List<Object>)root["path"]) {
|
|
|
PathConstraintData data = new PathConstraintData((string)constraintMap["name"]);
|
|
|
data.order = GetInt(constraintMap, "order", 0);
|
|
|
+ data.skinRequired = GetBoolean(constraintMap,"skin", false);
|
|
|
|
|
|
- foreach (string boneName in (List<Object>)constraintMap["bones"]) {
|
|
|
- BoneData bone = skeletonData.FindBone(boneName);
|
|
|
- if (bone == null) throw new Exception("Path bone not found: " + boneName);
|
|
|
- data.bones.Add(bone);
|
|
|
+ if (constraintMap.ContainsKey("bones")) {
|
|
|
+ foreach (string boneName in (List<Object>)constraintMap["bones"]) {
|
|
|
+ BoneData bone = skeletonData.FindBone(boneName);
|
|
|
+ if (bone == null) throw new Exception("Path bone not found: " + boneName);
|
|
|
+ data.bones.Add(bone);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
string targetName = (string)constraintMap["target"];
|
|
|
data.target = skeletonData.FindSlot(targetName);
|
|
|
- if (data.target == null) throw new Exception("Target slot not found: " + targetName);
|
|
|
+ if (data.target == null) throw new Exception("Path target slot not found: " + targetName);
|
|
|
|
|
|
data.positionMode = (PositionMode)Enum.Parse(typeof(PositionMode), GetString(constraintMap, "positionMode", "percent"), true);
|
|
|
data.spacingMode = (SpacingMode)Enum.Parse(typeof(SpacingMode), GetString(constraintMap, "spacingMode", "length"), true);
|
|
@@ -259,18 +271,48 @@ namespace Spine {
|
|
|
|
|
|
// Skins.
|
|
|
if (root.ContainsKey("skins")) {
|
|
|
- foreach (KeyValuePair<string, Object> skinMap in (Dictionary<string, Object>)root["skins"]) {
|
|
|
- var skin = new Skin(skinMap.Key);
|
|
|
- foreach (KeyValuePair<string, Object> slotEntry in (Dictionary<string, Object>)skinMap.Value) {
|
|
|
- int slotIndex = skeletonData.FindSlotIndex(slotEntry.Key);
|
|
|
- foreach (KeyValuePair<string, Object> entry in ((Dictionary<string, Object>)slotEntry.Value)) {
|
|
|
- try {
|
|
|
- Attachment attachment = ReadAttachment((Dictionary<string, Object>)entry.Value, skin, slotIndex, entry.Key, skeletonData);
|
|
|
- if (attachment != null) skin.AddAttachment(slotIndex, entry.Key, attachment);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new Exception("Error reading attachment: " + entry.Key + ", skin: " + skin, e);
|
|
|
- }
|
|
|
- }
|
|
|
+ foreach (Dictionary<string, object> skinMap in (List<object>)root["skins"]) {
|
|
|
+ Skin skin = new Skin((string)skinMap["name"]);
|
|
|
+ if (skinMap.ContainsKey("bones")) {
|
|
|
+ foreach (string entryName in (List<Object>)skinMap["bones"]) {
|
|
|
+ BoneData bone = skeletonData.FindBone(entryName);
|
|
|
+ if (bone == null) throw new Exception("Skin bone not found: " + entryName);
|
|
|
+ skin.bones.Add(bone);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (skinMap.ContainsKey("ik")) {
|
|
|
+ foreach (string entryName in (List<Object>)skinMap["ik"]) {
|
|
|
+ IkConstraintData constraint = skeletonData.FindIkConstraint(entryName);
|
|
|
+ if (constraint == null) throw new Exception("Skin IK constraint not found: " + entryName);
|
|
|
+ skin.constraints.Add(constraint);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (skinMap.ContainsKey("transform")) {
|
|
|
+ foreach (string entryName in (List<Object>)skinMap["transform"]) {
|
|
|
+ TransformConstraintData constraint = skeletonData.FindTransformConstraint(entryName);
|
|
|
+ if (constraint == null) throw new Exception("Skin transform constraint not found: " + entryName);
|
|
|
+ skin.constraints.Add(constraint);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (skinMap.ContainsKey("path")) {
|
|
|
+ foreach (string entryName in (List<Object>)skinMap["path"]) {
|
|
|
+ PathConstraintData constraint = skeletonData.FindPathConstraint(entryName);
|
|
|
+ if (constraint == null) throw new Exception("Skin path constraint not found: " + entryName);
|
|
|
+ skin.constraints.Add(constraint);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (skinMap.ContainsKey("attachments")) {
|
|
|
+ foreach (KeyValuePair<string, Object> slotEntry in (Dictionary<string, Object>)skinMap["attachments"]) {
|
|
|
+ int slotIndex = skeletonData.FindSlotIndex(slotEntry.Key);
|
|
|
+ foreach (KeyValuePair<string, Object> entry in ((Dictionary<string, Object>)slotEntry.Value)) {
|
|
|
+ try {
|
|
|
+ Attachment attachment = ReadAttachment((Dictionary<string, Object>)entry.Value, skin, slotIndex, entry.Key, skeletonData);
|
|
|
+ if (attachment != null) skin.SetAttachment(slotIndex, entry.Key, attachment);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new Exception("Error reading attachment: " + entry.Key + ", skin: " + skin, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
skeletonData.skins.Add(skin);
|
|
|
if (skin.name == "default") skeletonData.defaultSkin = skin;
|
|
@@ -494,7 +536,7 @@ namespace Spine {
|
|
|
|
|
|
int frameIndex = 0;
|
|
|
foreach (Dictionary<string, Object> valueMap in values) {
|
|
|
- float time = (float)valueMap["time"];
|
|
|
+ float time = GetFloat(valueMap, "time", 0);
|
|
|
timeline.SetFrame(frameIndex++, time, (string)valueMap["name"]);
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
@@ -506,7 +548,7 @@ namespace Spine {
|
|
|
|
|
|
int frameIndex = 0;
|
|
|
foreach (Dictionary<string, Object> valueMap in values) {
|
|
|
- float time = (float)valueMap["time"];
|
|
|
+ float time = GetFloat(valueMap, "time", 0);
|
|
|
string c = (string)valueMap["color"];
|
|
|
timeline.SetFrame(frameIndex, time, ToColor(c, 0), ToColor(c, 1), ToColor(c, 2), ToColor(c, 3));
|
|
|
ReadCurve(valueMap, timeline, frameIndex);
|
|
@@ -521,7 +563,7 @@ namespace Spine {
|
|
|
|
|
|
int frameIndex = 0;
|
|
|
foreach (Dictionary<string, Object> valueMap in values) {
|
|
|
- float time = (float)valueMap["time"];
|
|
|
+ float time = GetFloat(valueMap, "time", 0);
|
|
|
string light = (string)valueMap["light"];
|
|
|
string dark = (string)valueMap["dark"];
|
|
|
timeline.SetFrame(frameIndex, time, ToColor(light, 0), ToColor(light, 1), ToColor(light, 2), ToColor(light, 3),
|
|
@@ -554,7 +596,7 @@ namespace Spine {
|
|
|
|
|
|
int frameIndex = 0;
|
|
|
foreach (Dictionary<string, Object> valueMap in values) {
|
|
|
- timeline.SetFrame(frameIndex, (float)valueMap["time"], (float)valueMap["angle"]);
|
|
|
+ timeline.SetFrame(frameIndex, GetFloat(valueMap, "time", 0), GetFloat(valueMap, "angle", 0));
|
|
|
ReadCurve(valueMap, timeline, frameIndex);
|
|
|
frameIndex++;
|
|
|
}
|
|
@@ -563,9 +605,11 @@ namespace Spine {
|
|
|
|
|
|
} else if (timelineName == "translate" || timelineName == "scale" || timelineName == "shear") {
|
|
|
TranslateTimeline timeline;
|
|
|
- float timelineScale = 1;
|
|
|
- if (timelineName == "scale")
|
|
|
+ float timelineScale = 1, defaultValue = 0;
|
|
|
+ if (timelineName == "scale") {
|
|
|
timeline = new ScaleTimeline(values.Count);
|
|
|
+ defaultValue = 1;
|
|
|
+ }
|
|
|
else if (timelineName == "shear")
|
|
|
timeline = new ShearTimeline(values.Count);
|
|
|
else {
|
|
@@ -576,9 +620,9 @@ namespace Spine {
|
|
|
|
|
|
int frameIndex = 0;
|
|
|
foreach (Dictionary<string, Object> valueMap in values) {
|
|
|
- float time = (float)valueMap["time"];
|
|
|
- float x = GetFloat(valueMap, "x", 0);
|
|
|
- float y = GetFloat(valueMap, "y", 0);
|
|
|
+ float time = GetFloat(valueMap, "time", 0);
|
|
|
+ float x = GetFloat(valueMap, "x", defaultValue);
|
|
|
+ float y = GetFloat(valueMap, "y", defaultValue);
|
|
|
timeline.SetFrame(frameIndex, time, x * timelineScale, y * timelineScale);
|
|
|
ReadCurve(valueMap, timeline, frameIndex);
|
|
|
frameIndex++;
|
|
@@ -603,7 +647,7 @@ namespace Spine {
|
|
|
foreach (Dictionary<string, Object> valueMap in values) {
|
|
|
timeline.SetFrame(
|
|
|
frameIndex,
|
|
|
- (float)valueMap["time"],
|
|
|
+ GetFloat(valueMap, "time", 0),
|
|
|
GetFloat(valueMap, "mix", 1),
|
|
|
GetBoolean(valueMap, "bendPositive", true) ? 1 : -1,
|
|
|
GetBoolean(valueMap, "compress", true),
|
|
@@ -626,7 +670,7 @@ namespace Spine {
|
|
|
timeline.transformConstraintIndex = skeletonData.transformConstraints.IndexOf(constraint);
|
|
|
int frameIndex = 0;
|
|
|
foreach (Dictionary<string, Object> valueMap in values) {
|
|
|
- float time = (float)valueMap["time"];
|
|
|
+ float time = GetFloat(valueMap, "time", 0);
|
|
|
float rotateMix = GetFloat(valueMap, "rotateMix", 1);
|
|
|
float translateMix = GetFloat(valueMap, "translateMix", 1);
|
|
|
float scaleMix = GetFloat(valueMap, "scaleMix", 1);
|
|
@@ -641,8 +685,8 @@ namespace Spine {
|
|
|
}
|
|
|
|
|
|
// Path constraint timelines.
|
|
|
- if (map.ContainsKey("paths")) {
|
|
|
- foreach (KeyValuePair<string, Object> constraintMap in (Dictionary<string, Object>)map["paths"]) {
|
|
|
+ if (map.ContainsKey("path")) {
|
|
|
+ foreach (KeyValuePair<string, Object> constraintMap in (Dictionary<string, Object>)map["path"]) {
|
|
|
int index = skeletonData.FindPathConstraintIndex(constraintMap.Key);
|
|
|
if (index == -1) throw new Exception("Path constraint not found: " + constraintMap.Key);
|
|
|
PathConstraintData data = skeletonData.pathConstraints.Items[index];
|
|
@@ -664,7 +708,7 @@ namespace Spine {
|
|
|
timeline.pathConstraintIndex = index;
|
|
|
int frameIndex = 0;
|
|
|
foreach (Dictionary<string, Object> valueMap in values) {
|
|
|
- timeline.SetFrame(frameIndex, (float)valueMap["time"], GetFloat(valueMap, timelineName, 0) * timelineScale);
|
|
|
+ timeline.SetFrame(frameIndex, GetFloat(valueMap, "time", 0), GetFloat(valueMap, timelineName, 0) * timelineScale);
|
|
|
ReadCurve(valueMap, timeline, frameIndex);
|
|
|
frameIndex++;
|
|
|
}
|
|
@@ -676,7 +720,7 @@ namespace Spine {
|
|
|
timeline.pathConstraintIndex = index;
|
|
|
int frameIndex = 0;
|
|
|
foreach (Dictionary<string, Object> valueMap in values) {
|
|
|
- timeline.SetFrame(frameIndex, (float)valueMap["time"], GetFloat(valueMap, "rotateMix", 1), GetFloat(valueMap, "translateMix", 1));
|
|
|
+ timeline.SetFrame(frameIndex, GetFloat(valueMap, "time", 0), GetFloat(valueMap, "rotateMix", 1), GetFloat(valueMap, "translateMix", 1));
|
|
|
ReadCurve(valueMap, timeline, frameIndex);
|
|
|
frameIndex++;
|
|
|
}
|
|
@@ -727,7 +771,7 @@ namespace Spine {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- timeline.SetFrame(frameIndex, (float)valueMap["time"], deform);
|
|
|
+ timeline.SetFrame(frameIndex, GetFloat(valueMap, "time", 0), deform);
|
|
|
ReadCurve(valueMap, timeline, frameIndex);
|
|
|
frameIndex++;
|
|
|
}
|
|
@@ -770,7 +814,7 @@ namespace Spine {
|
|
|
for (int i = slotCount - 1; i >= 0; i--)
|
|
|
if (drawOrder[i] == -1) drawOrder[i] = unchanged[--unchangedIndex];
|
|
|
}
|
|
|
- timeline.SetFrame(frameIndex++, (float)drawOrderMap["time"], drawOrder);
|
|
|
+ timeline.SetFrame(frameIndex++, GetFloat(drawOrderMap, "time", 0), drawOrder);
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
|
duration = Math.Max(duration, timeline.frames[timeline.FrameCount - 1]);
|
|
@@ -784,7 +828,7 @@ namespace Spine {
|
|
|
foreach (Dictionary<string, Object> eventMap in eventsMap) {
|
|
|
EventData eventData = skeletonData.FindEvent((string)eventMap["name"]);
|
|
|
if (eventData == null) throw new Exception("Event not found: " + eventMap["name"]);
|
|
|
- var e = new Event((float)eventMap["time"], eventData) {
|
|
|
+ var e = new Event(GetFloat(eventMap, "time", 0), eventData) {
|
|
|
intValue = GetInt(eventMap, "int", eventData.Int),
|
|
|
floatValue = GetFloat(eventMap, "float", eventData.Float),
|
|
|
stringValue = GetString(eventMap, "string", eventData.String)
|
|
@@ -807,12 +851,12 @@ namespace Spine {
|
|
|
if (!valueMap.ContainsKey("curve"))
|
|
|
return;
|
|
|
Object curveObject = valueMap["curve"];
|
|
|
- if (curveObject.Equals("stepped"))
|
|
|
+ if (curveObject is string)
|
|
|
timeline.SetStepped(frameIndex);
|
|
|
else {
|
|
|
var curve = curveObject as List<Object>;
|
|
|
if (curve != null)
|
|
|
- timeline.SetCurve(frameIndex, (float)curve[0], (float)curve[1], (float)curve[2], (float)curve[3]);
|
|
|
+ timeline.SetCurve(frameIndex, (float)curveObject, GetFloat(valueMap, "c2", 0), GetFloat(valueMap, "c3", 1), GetFloat(valueMap, "c4", 1));
|
|
|
}
|
|
|
}
|
|
|
|