|
@@ -42,6 +42,21 @@ using Windows.Storage;
|
|
|
|
|
|
namespace Spine {
|
|
|
|
|
|
+ using FromProperty = TransformConstraintData.FromProperty;
|
|
|
+ using FromRotate = TransformConstraintData.FromRotate;
|
|
|
+ using FromScaleX = TransformConstraintData.FromScaleX;
|
|
|
+ using FromScaleY = TransformConstraintData.FromScaleY;
|
|
|
+ using FromShearY = TransformConstraintData.FromShearY;
|
|
|
+ using FromX = TransformConstraintData.FromX;
|
|
|
+ using FromY = TransformConstraintData.FromY;
|
|
|
+ using ToProperty = TransformConstraintData.ToProperty;
|
|
|
+ using ToRotate = TransformConstraintData.ToRotate;
|
|
|
+ using ToScaleX = TransformConstraintData.ToScaleX;
|
|
|
+ using ToScaleY = TransformConstraintData.ToScaleY;
|
|
|
+ using ToShearY = TransformConstraintData.ToShearY;
|
|
|
+ using ToX = TransformConstraintData.ToX;
|
|
|
+ using ToY = TransformConstraintData.ToY;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Loads skeleton data in the Spine JSON format.
|
|
|
/// <para>
|
|
@@ -94,7 +109,7 @@ namespace Spine {
|
|
|
if (reader == null) throw new ArgumentNullException("reader", "reader cannot be null.");
|
|
|
|
|
|
float scale = this.scale;
|
|
|
- SkeletonData skeletonData = new SkeletonData();
|
|
|
+ var skeletonData = new SkeletonData();
|
|
|
|
|
|
Dictionary<string, object> root = Json.Deserialize(reader) as Dictionary<string, Object>;
|
|
|
if (root == null) throw new Exception("Invalid JSON.");
|
|
@@ -123,7 +138,7 @@ namespace Spine {
|
|
|
if (parent == null)
|
|
|
throw new Exception("Parent bone not found: " + boneMap["parent"]);
|
|
|
}
|
|
|
- BoneData data = new BoneData(skeletonData.Bones.Count, (string)boneMap["name"], 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;
|
|
@@ -148,7 +163,7 @@ namespace Spine {
|
|
|
string boneName = (string)slotMap["bone"];
|
|
|
BoneData boneData = skeletonData.FindBone(boneName);
|
|
|
if (boneData == null) throw new Exception("Slot bone not found: " + boneName);
|
|
|
- SlotData data = new SlotData(skeletonData.Slots.Count, slotName, boneData);
|
|
|
+ var data = new SlotData(skeletonData.Slots.Count, slotName, boneData);
|
|
|
|
|
|
if (slotMap.ContainsKey("color")) {
|
|
|
string color = (string)slotMap["color"];
|
|
@@ -179,7 +194,7 @@ namespace Spine {
|
|
|
// IK constraints.
|
|
|
if (root.ContainsKey("ik")) {
|
|
|
foreach (Dictionary<string, Object> constraintMap in (List<Object>)root["ik"]) {
|
|
|
- IkConstraintData data = new IkConstraintData((string)constraintMap["name"]);
|
|
|
+ var data = new IkConstraintData((string)constraintMap["name"]);
|
|
|
data.order = GetInt(constraintMap, "order", 0);
|
|
|
data.skinRequired = GetBoolean(constraintMap, "skin", false);
|
|
|
|
|
@@ -208,7 +223,7 @@ namespace Spine {
|
|
|
// Transform constraints.
|
|
|
if (root.ContainsKey("transform")) {
|
|
|
foreach (Dictionary<string, Object> constraintMap in (List<Object>)root["transform"]) {
|
|
|
- TransformConstraintData data = new TransformConstraintData((string)constraintMap["name"]);
|
|
|
+ var data = new TransformConstraintData((string)constraintMap["name"]);
|
|
|
data.order = GetInt(constraintMap, "order", 0);
|
|
|
data.skinRequired = GetBoolean(constraintMap, "skin", false);
|
|
|
|
|
@@ -220,26 +235,89 @@ namespace Spine {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- string targetName = (string)constraintMap["target"];
|
|
|
- data.target = skeletonData.FindBone(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);
|
|
|
-
|
|
|
- data.offsetRotation = GetFloat(constraintMap, "rotation", 0);
|
|
|
- data.offsetX = GetFloat(constraintMap, "x", 0) * scale;
|
|
|
- data.offsetY = GetFloat(constraintMap, "y", 0) * scale;
|
|
|
- data.offsetScaleX = GetFloat(constraintMap, "scaleX", 0);
|
|
|
- data.offsetScaleY = GetFloat(constraintMap, "scaleY", 0);
|
|
|
- data.offsetShearY = GetFloat(constraintMap, "shearY", 0);
|
|
|
+ string sourceName = (string)constraintMap["source"];
|
|
|
+ data.source = skeletonData.FindBone(sourceName);
|
|
|
+ if (data.source == null) throw new Exception("Transform constraint source bone not found: " + sourceName);
|
|
|
+
|
|
|
+ data.localSource = GetBoolean(constraintMap, "localSource", false);
|
|
|
+ data.additive = GetBoolean(constraintMap, "additive", false);
|
|
|
+ data.clamp = GetBoolean(constraintMap, "clamp", false);
|
|
|
+
|
|
|
+ bool rotate = false, x = false, y = false, scaleX = false, scaleY = false, shearY = false;
|
|
|
+ if (constraintMap.ContainsKey("properties")) {
|
|
|
+ foreach (KeyValuePair<string, Object> fromEntryObject in (Dictionary<string, Object>)constraintMap["properties"]) {
|
|
|
+ var fromEntry = (Dictionary<string, Object>)fromEntryObject.Value;
|
|
|
+ string fromEntryName = fromEntryObject.Key;
|
|
|
+
|
|
|
+ FromProperty from;
|
|
|
+ switch (fromEntryName) {
|
|
|
+ case "rotate": from = new FromRotate(); break;
|
|
|
+ case "x": from = new FromX(); break;
|
|
|
+ case "y": from = new FromY(); break;
|
|
|
+ case "scaleX": from = new FromScaleX(); break;
|
|
|
+ case "scaleY": from = new FromScaleY(); break;
|
|
|
+ case "shearY": from = new FromShearY(); break;
|
|
|
+ default: throw new Exception("Invalid transform constraint from property: " + fromEntryName);
|
|
|
+ };
|
|
|
+
|
|
|
+ from.offset = GetFloat(fromEntry, "offset", 0) * scale;
|
|
|
+ if (fromEntry.ContainsKey("to")) {
|
|
|
+ foreach (KeyValuePair<string, Object> toEntryObject in (Dictionary<string, Object>)fromEntry["to"]) {
|
|
|
+ var toEntry = (Dictionary<string, Object>)toEntryObject.Value;
|
|
|
+ string toEntryName = toEntryObject.Key;
|
|
|
+
|
|
|
+ ToProperty to;
|
|
|
+ switch (toEntryName) {
|
|
|
+ case "rotate": {
|
|
|
+ rotate = true;
|
|
|
+ to = new ToRotate();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "x": {
|
|
|
+ x = true;
|
|
|
+ to = new ToX();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "y": {
|
|
|
+ y = true;
|
|
|
+ to = new ToY();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "scaleX": {
|
|
|
+ scaleX = true;
|
|
|
+ to = new ToScaleX();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "scaleY": {
|
|
|
+ scaleY = true;
|
|
|
+ to = new ToScaleY();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "shearY": {
|
|
|
+ shearY = true;
|
|
|
+ to = new ToShearY();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default: throw new Exception("Invalid transform constraint to property: " + toEntryName);
|
|
|
+ }
|
|
|
+ to.offset = GetFloat(toEntry, "offset", 0) * scale;
|
|
|
+ to.max = GetFloat(toEntry, "max", 1) * scale;
|
|
|
+ to.scale = GetFloat(toEntry, "scale");
|
|
|
+ from.to.Add(to);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (from.to.Count != 0) data.properties.Add(from);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- data.mixRotate = GetFloat(constraintMap, "mixRotate", 1);
|
|
|
- data.mixX = GetFloat(constraintMap, "mixX", 1);
|
|
|
- data.mixY = GetFloat(constraintMap, "mixY", data.mixX);
|
|
|
- data.mixScaleX = GetFloat(constraintMap, "mixScaleX", 1);
|
|
|
- data.mixScaleY = GetFloat(constraintMap, "mixScaleY", data.mixScaleX);
|
|
|
- data.mixShearY = GetFloat(constraintMap, "mixShearY", 1);
|
|
|
+ data.offsetX = GetFloat(constraintMap, "x", 0);
|
|
|
+ data.offsetY = GetFloat(constraintMap, "y", 0);
|
|
|
+ if (rotate) data.mixRotate = GetFloat(constraintMap, "mixRotate", 1);
|
|
|
+ if (x) data.mixX = GetFloat(constraintMap, "mixX", 1);
|
|
|
+ if (y) data.mixY = GetFloat(constraintMap, "mixY", data.mixX);
|
|
|
+ if (scaleX) data.mixScaleX = GetFloat(constraintMap, "mixScaleX", 1);
|
|
|
+ if (scaleY) data.mixScaleY = GetFloat(constraintMap, "mixScaleY", data.mixScaleX);
|
|
|
+ if (shearY) data.mixShearY = GetFloat(constraintMap, "mixShearY", 1);
|
|
|
|
|
|
skeletonData.transformConstraints.Add(data);
|
|
|
}
|
|
@@ -248,7 +326,7 @@ namespace Spine {
|
|
|
// Path constraints.
|
|
|
if (root.ContainsKey("path")) {
|
|
|
foreach (Dictionary<string, Object> constraintMap in (List<Object>)root["path"]) {
|
|
|
- PathConstraintData data = new PathConstraintData((string)constraintMap["name"]);
|
|
|
+ var data = new PathConstraintData((string)constraintMap["name"]);
|
|
|
data.order = GetInt(constraintMap, "order", 0);
|
|
|
data.skinRequired = GetBoolean(constraintMap, "skin", false);
|
|
|
|
|
@@ -260,9 +338,9 @@ namespace Spine {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- string targetName = (string)constraintMap["target"];
|
|
|
- data.target = skeletonData.FindSlot(targetName);
|
|
|
- if (data.target == null) throw new Exception("Path target slot not found: " + targetName);
|
|
|
+ string slotName = (string)constraintMap["slot"];
|
|
|
+ data.slot = skeletonData.FindSlot(slotName);
|
|
|
+ if (data.slot == null) throw new Exception("Path slot not found: " + slotName);
|
|
|
|
|
|
data.positionMode = (PositionMode)Enum.Parse(typeof(PositionMode), GetString(constraintMap, "positionMode", "percent"), true);
|
|
|
data.spacingMode = (SpacingMode)Enum.Parse(typeof(SpacingMode), GetString(constraintMap, "spacingMode", "length"), true);
|
|
@@ -283,7 +361,7 @@ namespace Spine {
|
|
|
// Physics constraints.
|
|
|
if (root.ContainsKey("physics")) {
|
|
|
foreach (Dictionary<string, Object> constraintMap in (List<Object>)root["physics"]) {
|
|
|
- PhysicsConstraintData data = new PhysicsConstraintData((string)constraintMap["name"]);
|
|
|
+ var data = new PhysicsConstraintData((string)constraintMap["name"]);
|
|
|
data.order = GetInt(constraintMap, "order", 0);
|
|
|
data.skinRequired = GetBoolean(constraintMap, "skin", false);
|
|
|
|
|
@@ -320,7 +398,7 @@ namespace Spine {
|
|
|
// Skins.
|
|
|
if (root.ContainsKey("skins")) {
|
|
|
foreach (Dictionary<string, object> skinMap in (List<object>)root["skins"]) {
|
|
|
- Skin skin = new Skin((string)skinMap["name"]);
|
|
|
+ var skin = new Skin((string)skinMap["name"]);
|
|
|
if (skinMap.ContainsKey("bones")) {
|
|
|
foreach (string entryName in (List<Object>)skinMap["bones"]) {
|
|
|
BoneData bone = skeletonData.FindBone(entryName);
|
|
@@ -393,7 +471,7 @@ namespace Spine {
|
|
|
if (root.ContainsKey("events")) {
|
|
|
foreach (KeyValuePair<string, Object> entry in (Dictionary<string, Object>)root["events"]) {
|
|
|
Dictionary<string, object> entryMap = (Dictionary<string, Object>)entry.Value;
|
|
|
- EventData data = new EventData(entry.Key);
|
|
|
+ var data = new EventData(entry.Key);
|
|
|
data.Int = GetInt(entryMap, "int", 0);
|
|
|
data.Float = GetFloat(entryMap, "float", 0);
|
|
|
data.String = GetString(entryMap, "string", string.Empty);
|
|
@@ -553,7 +631,7 @@ namespace Spine {
|
|
|
public static Sequence ReadSequence (object sequenceJson) {
|
|
|
Dictionary<string, object> map = sequenceJson as Dictionary<string, Object>;
|
|
|
if (map == null) return null;
|
|
|
- Sequence sequence = new Sequence(GetInt(map, "count"));
|
|
|
+ var sequence = new Sequence(GetInt(map, "count"));
|
|
|
sequence.start = GetInt(map, "start", 1);
|
|
|
sequence.digits = GetInt(map, "digits", 0);
|
|
|
sequence.setupIndex = GetInt(map, "setup", 0);
|
|
@@ -573,8 +651,8 @@ namespace Spine {
|
|
|
attachment.vertices = vertices;
|
|
|
return;
|
|
|
}
|
|
|
- ExposedList<float> weights = new ExposedList<float>(verticesLength * 3 * 3);
|
|
|
- ExposedList<int> bones = new ExposedList<int>(verticesLength * 3);
|
|
|
+ var weights = new ExposedList<float>(verticesLength * 3 * 3);
|
|
|
+ var bones = new ExposedList<int>(verticesLength * 3);
|
|
|
for (int i = 0, n = vertices.Length; i < n;) {
|
|
|
int boneCount = (int)vertices[i++];
|
|
|
bones.Add(boneCount);
|
|
@@ -598,7 +676,7 @@ namespace Spine {
|
|
|
|
|
|
private void ReadAnimation (Dictionary<string, Object> map, string name, SkeletonData skeletonData) {
|
|
|
float scale = this.scale;
|
|
|
- ExposedList<Timeline> timelines = new ExposedList<Timeline>();
|
|
|
+ var timelines = new ExposedList<Timeline>();
|
|
|
|
|
|
// Slot timelines.
|
|
|
if (map.ContainsKey("slots")) {
|
|
@@ -611,16 +689,18 @@ namespace Spine {
|
|
|
int frames = values.Count;
|
|
|
if (frames == 0) continue;
|
|
|
string timelineName = (string)timelineEntry.Key;
|
|
|
- if (timelineName == "attachment") {
|
|
|
- AttachmentTimeline timeline = new AttachmentTimeline(frames, slotIndex);
|
|
|
+ switch (timelineName) {
|
|
|
+ case "attachment": {
|
|
|
+ var timeline = new AttachmentTimeline(frames, slotIndex);
|
|
|
int frame = 0;
|
|
|
foreach (Dictionary<string, Object> keyMap in values) {
|
|
|
timeline.SetFrame(frame++, GetFloat(keyMap, "time", 0), GetString(keyMap, "name", null));
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
|
-
|
|
|
- } else if (timelineName == "rgba") {
|
|
|
- RGBATimeline timeline = new RGBATimeline(frames, frames << 2, slotIndex);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "rgba": {
|
|
|
+ var timeline = new RGBATimeline(frames, frames << 2, slotIndex);
|
|
|
|
|
|
List<object>.Enumerator keyMapEnumerator = values.GetEnumerator();
|
|
|
keyMapEnumerator.MoveNext();
|
|
@@ -661,9 +741,10 @@ namespace Spine {
|
|
|
keyMap = nextMap;
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
|
-
|
|
|
- } else if (timelineName == "rgb") {
|
|
|
- RGBTimeline timeline = new RGBTimeline(frames, frames * 3, slotIndex);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "rgb": {
|
|
|
+ var timeline = new RGBTimeline(frames, frames * 3, slotIndex);
|
|
|
|
|
|
List<object>.Enumerator keyMapEnumerator = values.GetEnumerator();
|
|
|
keyMapEnumerator.MoveNext();
|
|
@@ -700,14 +781,16 @@ namespace Spine {
|
|
|
keyMap = nextMap;
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
|
-
|
|
|
- } else if (timelineName == "alpha") {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "alpha": {
|
|
|
List<object>.Enumerator keyMapEnumerator = values.GetEnumerator();
|
|
|
keyMapEnumerator.MoveNext();
|
|
|
timelines.Add(ReadTimeline(ref keyMapEnumerator, new AlphaTimeline(frames, frames, slotIndex), 0, 1));
|
|
|
-
|
|
|
- } else if (timelineName == "rgba2") {
|
|
|
- RGBA2Timeline timeline = new RGBA2Timeline(frames, frames * 7, slotIndex);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "rgba2": {
|
|
|
+ var timeline = new RGBA2Timeline(frames, frames * 7, slotIndex);
|
|
|
|
|
|
List<object>.Enumerator keyMapEnumerator = values.GetEnumerator();
|
|
|
keyMapEnumerator.MoveNext();
|
|
@@ -762,9 +845,10 @@ namespace Spine {
|
|
|
keyMap = nextMap;
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
|
-
|
|
|
- } else if (timelineName == "rgb2") {
|
|
|
- RGB2Timeline timeline = new RGB2Timeline(frames, frames * 6, slotIndex);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "rgb2": {
|
|
|
+ var timeline = new RGB2Timeline(frames, frames * 6, slotIndex);
|
|
|
|
|
|
List<object>.Enumerator keyMapEnumerator = values.GetEnumerator();
|
|
|
keyMapEnumerator.MoveNext();
|
|
@@ -815,9 +899,11 @@ namespace Spine {
|
|
|
keyMap = nextMap;
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
|
-
|
|
|
- } else
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
throw new Exception("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -842,33 +928,46 @@ namespace Spine {
|
|
|
if (!keyMapEnumerator.MoveNext()) continue;
|
|
|
int frames = values.Count;
|
|
|
string timelineName = (string)timelineEntry.Key;
|
|
|
- if (timelineName == "rotate")
|
|
|
+ switch (timelineName) {
|
|
|
+ case "rotate":
|
|
|
timelines.Add(ReadTimeline(ref keyMapEnumerator, new RotateTimeline(frames, frames, boneIndex), 0, 1));
|
|
|
- else if (timelineName == "translate") {
|
|
|
- TranslateTimeline timeline = new TranslateTimeline(frames, frames << 1, boneIndex);
|
|
|
- timelines.Add(ReadTimeline(ref keyMapEnumerator, timeline, "x", "y", 0, scale));
|
|
|
- } else if (timelineName == "translatex") {
|
|
|
+ break;
|
|
|
+ case "translate": {
|
|
|
+ timelines.Add(ReadTimeline(ref keyMapEnumerator, new TranslateTimeline(frames, frames << 1, boneIndex), "x", "y", 0, scale));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "translatex": {
|
|
|
timelines
|
|
|
.Add(ReadTimeline(ref keyMapEnumerator, new TranslateXTimeline(frames, frames, boneIndex), 0, scale));
|
|
|
- } else if (timelineName == "translatey") {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "translatey": {
|
|
|
timelines
|
|
|
.Add(ReadTimeline(ref keyMapEnumerator, new TranslateYTimeline(frames, frames, boneIndex), 0, scale));
|
|
|
- } else if (timelineName == "scale") {
|
|
|
- ScaleTimeline timeline = new ScaleTimeline(frames, frames << 1, boneIndex);
|
|
|
- timelines.Add(ReadTimeline(ref keyMapEnumerator, timeline, "x", "y", 1, 1));
|
|
|
- } else if (timelineName == "scalex")
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "scale": {
|
|
|
+ timelines.Add(ReadTimeline(ref keyMapEnumerator, new ScaleTimeline(frames, frames << 1, boneIndex), "x", "y", 1, 1));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "scalex":
|
|
|
timelines.Add(ReadTimeline(ref keyMapEnumerator, new ScaleXTimeline(frames, frames, boneIndex), 1, 1));
|
|
|
- else if (timelineName == "scaley")
|
|
|
+ break;
|
|
|
+ case "scaley":
|
|
|
timelines.Add(ReadTimeline(ref keyMapEnumerator, new ScaleYTimeline(frames, frames, boneIndex), 1, 1));
|
|
|
- else if (timelineName == "shear") {
|
|
|
- ShearTimeline timeline = new ShearTimeline(frames, frames << 1, boneIndex);
|
|
|
- timelines.Add(ReadTimeline(ref keyMapEnumerator, timeline, "x", "y", 0, 1));
|
|
|
- } else if (timelineName == "shearx")
|
|
|
+ break;
|
|
|
+ case "shear": {
|
|
|
+ timelines.Add(ReadTimeline(ref keyMapEnumerator, new ShearTimeline(frames, frames << 1, boneIndex), "x", "y", 0, 1));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "shearx":
|
|
|
timelines.Add(ReadTimeline(ref keyMapEnumerator, new ShearXTimeline(frames, frames, boneIndex), 0, 1));
|
|
|
- else if (timelineName == "sheary")
|
|
|
+ break;
|
|
|
+ case "sheary":
|
|
|
timelines.Add(ReadTimeline(ref keyMapEnumerator, new ShearYTimeline(frames, frames, boneIndex), 0, 1));
|
|
|
- else if (timelineName == "inherit") {
|
|
|
- InheritTimeline timeline = new InheritTimeline(frames, boneIndex);
|
|
|
+ break;
|
|
|
+ case "inherit": {
|
|
|
+ var timeline = new InheritTimeline(frames, boneIndex);
|
|
|
for (int frame = 0; ; frame++) {
|
|
|
Dictionary<string, object> keyMap = (Dictionary<string, Object>)keyMapEnumerator.Current;
|
|
|
float time = GetFloat(keyMap, "time", 0);
|
|
@@ -879,8 +978,11 @@ namespace Spine {
|
|
|
}
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
|
- } else
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
throw new Exception("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -893,7 +995,7 @@ namespace Spine {
|
|
|
if (!keyMapEnumerator.MoveNext()) continue;
|
|
|
Dictionary<string, object> keyMap = (Dictionary<string, Object>)keyMapEnumerator.Current;
|
|
|
IkConstraintData constraint = skeletonData.FindIkConstraint(timelineMap.Key);
|
|
|
- IkConstraintTimeline timeline = new IkConstraintTimeline(values.Count, values.Count << 1,
|
|
|
+ var timeline = new IkConstraintTimeline(values.Count, values.Count << 1,
|
|
|
skeletonData.IkConstraints.IndexOf(constraint));
|
|
|
float time = GetFloat(keyMap, "time", 0);
|
|
|
float mix = GetFloat(keyMap, "mix", 1), softness = GetFloat(keyMap, "softness", 0) * scale;
|
|
@@ -929,7 +1031,7 @@ namespace Spine {
|
|
|
if (!keyMapEnumerator.MoveNext()) continue;
|
|
|
Dictionary<string, object> keyMap = (Dictionary<string, Object>)keyMapEnumerator.Current;
|
|
|
TransformConstraintData constraint = skeletonData.FindTransformConstraint(timelineMap.Key);
|
|
|
- TransformConstraintTimeline timeline = new TransformConstraintTimeline(values.Count, values.Count * 6,
|
|
|
+ var timeline = new TransformConstraintTimeline(values.Count, values.Count * 6,
|
|
|
skeletonData.TransformConstraints.IndexOf(constraint));
|
|
|
float time = GetFloat(keyMap, "time", 0);
|
|
|
float mixRotate = GetFloat(keyMap, "mixRotate", 1), mixShearY = GetFloat(keyMap, "mixShearY", 1);
|
|
@@ -982,15 +1084,20 @@ namespace Spine {
|
|
|
|
|
|
int frames = values.Count;
|
|
|
string timelineName = (string)timelineEntry.Key;
|
|
|
- if (timelineName == "position") {
|
|
|
+ switch (timelineName) {
|
|
|
+ case "position": {
|
|
|
CurveTimeline1 timeline = new PathConstraintPositionTimeline(frames, frames, constraintIndex);
|
|
|
timelines.Add(ReadTimeline(ref keyMapEnumerator, timeline, 0, constraint.positionMode == PositionMode.Fixed ? scale : 1));
|
|
|
- } else if (timelineName == "spacing") {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "spacing": {
|
|
|
CurveTimeline1 timeline = new PathConstraintSpacingTimeline(frames, frames, constraintIndex);
|
|
|
timelines.Add(ReadTimeline(ref keyMapEnumerator, timeline, 0,
|
|
|
constraint.spacingMode == SpacingMode.Length || constraint.spacingMode == SpacingMode.Fixed ? scale : 1));
|
|
|
- } else if (timelineName == "mix") {
|
|
|
- PathConstraintMixTimeline timeline = new PathConstraintMixTimeline(frames, frames * 3, constraintIndex);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "mix": {
|
|
|
+ var timeline = new PathConstraintMixTimeline(frames, frames * 3, constraintIndex);
|
|
|
Dictionary<string, object> keyMap = (Dictionary<string, Object>)keyMapEnumerator.Current;
|
|
|
float time = GetFloat(keyMap, "time", 0);
|
|
|
float mixRotate = GetFloat(keyMap, "mixRotate", 1);
|
|
@@ -1018,6 +1125,8 @@ namespace Spine {
|
|
|
keyMap = nextMap;
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1040,33 +1149,41 @@ namespace Spine {
|
|
|
|
|
|
int frames = values.Count;
|
|
|
string timelineName = (string)timelineEntry.Key;
|
|
|
- if (timelineName == "reset") {
|
|
|
- PhysicsConstraintResetTimeline timeline1 = new PhysicsConstraintResetTimeline(frames, index);
|
|
|
+ CurveTimeline1 timeline;
|
|
|
+ switch (timelineName) {
|
|
|
+ case "reset": {
|
|
|
+ var resetTimeline = new PhysicsConstraintResetTimeline(frames, index);
|
|
|
int frame = 0;
|
|
|
foreach (Dictionary<string, Object> keyMap in values) {
|
|
|
- timeline1.SetFrame(frame++, GetFloat(keyMap, "time", 0));
|
|
|
+ resetTimeline.SetFrame(frame++, GetFloat(keyMap, "time", 0));
|
|
|
}
|
|
|
- timelines.Add(timeline1);
|
|
|
+ timelines.Add(resetTimeline);
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- CurveTimeline1 timeline;
|
|
|
- if (timelineName == "inertia")
|
|
|
+ case "inertia":
|
|
|
timeline = new PhysicsConstraintInertiaTimeline(frames, frames, index);
|
|
|
- else if (timelineName == "strength")
|
|
|
+ break;
|
|
|
+ case "strength":
|
|
|
timeline = new PhysicsConstraintStrengthTimeline(frames, frames, index);
|
|
|
- else if (timelineName == "damping")
|
|
|
+ break;
|
|
|
+ case "damping":
|
|
|
timeline = new PhysicsConstraintDampingTimeline(frames, frames, index);
|
|
|
- else if (timelineName == "mass")
|
|
|
+ break;
|
|
|
+ case "mass":
|
|
|
timeline = new PhysicsConstraintMassTimeline(frames, frames, index);
|
|
|
- else if (timelineName == "wind")
|
|
|
+ break;
|
|
|
+ case "wind":
|
|
|
timeline = new PhysicsConstraintWindTimeline(frames, frames, index);
|
|
|
- else if (timelineName == "gravity")
|
|
|
+ break;
|
|
|
+ case "gravity":
|
|
|
timeline = new PhysicsConstraintGravityTimeline(frames, frames, index);
|
|
|
- else if (timelineName == "mix") //
|
|
|
+ break;
|
|
|
+ case "mix":
|
|
|
timeline = new PhysicsConstraintMixTimeline(frames, frames, index);
|
|
|
- else
|
|
|
+ break;
|
|
|
+ default:
|
|
|
continue;
|
|
|
+ }
|
|
|
timelines.Add(ReadTimeline(ref keyMapEnumerator, timeline, 0, 1));
|
|
|
}
|
|
|
}
|
|
@@ -1089,13 +1206,14 @@ namespace Spine {
|
|
|
Dictionary<string, object> keyMap = (Dictionary<string, Object>)keyMapEnumerator.Current;
|
|
|
int frames = values.Count;
|
|
|
string timelineName = timelineMap.Key;
|
|
|
- if (timelineName == "deform") {
|
|
|
+ switch (timelineName) {
|
|
|
+ case "deform": {
|
|
|
VertexAttachment vertexAttachment = (VertexAttachment)attachment;
|
|
|
bool weighted = vertexAttachment.bones != null;
|
|
|
float[] vertices = vertexAttachment.vertices;
|
|
|
int deformLength = weighted ? (vertices.Length / 3) << 1 : vertices.Length;
|
|
|
|
|
|
- DeformTimeline timeline = new DeformTimeline(frames, frames, slot.Index, vertexAttachment);
|
|
|
+ var timeline = new DeformTimeline(frames, frames, slot.Index, vertexAttachment);
|
|
|
float time = GetFloat(keyMap, "time", 0);
|
|
|
for (int frame = 0, bezier = 0; ; frame++) {
|
|
|
float[] deform;
|
|
@@ -1132,8 +1250,10 @@ namespace Spine {
|
|
|
keyMap = nextMap;
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
|
- } else if (timelineName == "sequence") {
|
|
|
- SequenceTimeline timeline = new SequenceTimeline(frames, slot.index, attachment);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case "sequence": {
|
|
|
+ var timeline = new SequenceTimeline(frames, slot.index, attachment);
|
|
|
float lastDelay = 0;
|
|
|
for (int frame = 0; keyMap != null; keyMap = keyMapEnumerator.MoveNext() ?
|
|
|
(Dictionary<string, Object>)keyMapEnumerator.Current : null, frame++) {
|
|
@@ -1146,6 +1266,8 @@ namespace Spine {
|
|
|
lastDelay = delay;
|
|
|
}
|
|
|
timelines.Add(timeline);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1156,7 +1278,7 @@ namespace Spine {
|
|
|
// Draw order timeline.
|
|
|
if (map.ContainsKey("drawOrder")) {
|
|
|
List<object> values = (List<Object>)map["drawOrder"];
|
|
|
- DrawOrderTimeline timeline = new DrawOrderTimeline(values.Count);
|
|
|
+ var timeline = new DrawOrderTimeline(values.Count);
|
|
|
int slotCount = skeletonData.slots.Count;
|
|
|
int frame = 0;
|
|
|
foreach (Dictionary<string, Object> keyMap in values) {
|
|
@@ -1193,12 +1315,12 @@ namespace Spine {
|
|
|
// Event timeline.
|
|
|
if (map.ContainsKey("events")) {
|
|
|
List<object> eventsMap = (List<Object>)map["events"];
|
|
|
- EventTimeline timeline = new EventTimeline(eventsMap.Count);
|
|
|
+ var timeline = new EventTimeline(eventsMap.Count);
|
|
|
int frame = 0;
|
|
|
foreach (Dictionary<string, Object> keyMap in eventsMap) {
|
|
|
EventData eventData = skeletonData.FindEvent((string)keyMap["name"]);
|
|
|
if (eventData == null) throw new Exception("Event not found: " + keyMap["name"]);
|
|
|
- Event e = new Event(GetFloat(keyMap, "time", 0), eventData) {
|
|
|
+ var e = new Event(GetFloat(keyMap, "time", 0), eventData) {
|
|
|
intValue = GetInt(keyMap, "int", eventData.Int),
|
|
|
floatValue = GetFloat(keyMap, "float", eventData.Float),
|
|
|
stringValue = GetString(keyMap, "string", eventData.String)
|
|
@@ -1319,6 +1441,11 @@ namespace Spine {
|
|
|
return (float)map[name];
|
|
|
}
|
|
|
|
|
|
+ static float GetFloat (Dictionary<string, Object> map, string name) {
|
|
|
+ if (!map.ContainsKey(name)) throw new ArgumentException("Named value not found: " + name);
|
|
|
+ return (float)map[name];
|
|
|
+ }
|
|
|
+
|
|
|
static int GetInt (Dictionary<string, Object> map, string name, int defaultValue) {
|
|
|
if (!map.ContainsKey(name)) return defaultValue;
|
|
|
return (int)(float)map[name];
|