From 803a8ab04592227c9d16fdbff1eb3425dfc24e64 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Tue, 23 Apr 2013 21:53:36 +0200 Subject: [PATCH] Fixed animations with no bone keys. --- spine-csharp/src/SkeletonJson.cs | 102 ++++++++++++++++--------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index e4fd2242d..af7b31594 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -114,7 +114,7 @@ namespace Spine { // Skins. if (root.ContainsKey("skins")) { - Dictionary skinMap = (Dictionary)root["skins"]; + var skinMap = (Dictionary)root["skins"]; foreach (KeyValuePair entry in skinMap) { Skin skin = new Skin(entry.Key); foreach (KeyValuePair slotEntry in (Dictionary)entry.Value) { @@ -133,7 +133,7 @@ namespace Spine { // Animations. if (root.ContainsKey("animations")) { - Dictionary animationMap = (Dictionary)root["animations"]; + var animationMap = (Dictionary)root["animations"]; foreach (KeyValuePair entry in animationMap) ReadAnimation(entry.Key, (Dictionary)entry.Value, skeletonData); } @@ -185,68 +185,70 @@ namespace Spine { var timelines = new List(); float duration = 0; - var bonesMap = (Dictionary)map["bones"]; - foreach (KeyValuePair entry in bonesMap) { - String boneName = entry.Key; - int boneIndex = skeletonData.FindBoneIndex(boneName); - if (boneIndex == -1) - throw new Exception("Bone not found: " + boneName); + if (map.ContainsKey("bones")) { + var bonesMap = (Dictionary)map["bones"]; + foreach (KeyValuePair entry in bonesMap) { + String boneName = entry.Key; + int boneIndex = skeletonData.FindBoneIndex(boneName); + if (boneIndex == -1) + throw new Exception("Bone not found: " + boneName); - Dictionary timelineMap = (Dictionary)entry.Value; - foreach (KeyValuePair timelineEntry in timelineMap) { - List values = (List)timelineEntry.Value; - String timelineName = (String)timelineEntry.Key; - if (timelineName.Equals(TIMELINE_ROTATE)) { - RotateTimeline timeline = new RotateTimeline(values.Count); - timeline.BoneIndex = boneIndex; + var timelineMap = (Dictionary)entry.Value; + foreach (KeyValuePair timelineEntry in timelineMap) { + var values = (List)timelineEntry.Value; + String timelineName = (String)timelineEntry.Key; + if (timelineName.Equals(TIMELINE_ROTATE)) { + RotateTimeline timeline = new RotateTimeline(values.Count); + timeline.BoneIndex = boneIndex; - int frameIndex = 0; - foreach (Dictionary valueMap in values) { - float time = (float)valueMap["time"]; - timeline.SetFrame(frameIndex, time, (float)valueMap["angle"]); - ReadCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.Add(timeline); - duration = Math.Max(duration, timeline.Frames[timeline.FrameCount * 2 - 2]); + int frameIndex = 0; + foreach (Dictionary valueMap in values) { + float time = (float)valueMap["time"]; + timeline.SetFrame(frameIndex, time, (float)valueMap["angle"]); + ReadCurve(timeline, frameIndex, valueMap); + frameIndex++; + } + timelines.Add(timeline); + duration = Math.Max(duration, timeline.Frames[timeline.FrameCount * 2 - 2]); - } else if (timelineName.Equals(TIMELINE_TRANSLATE) || timelineName.Equals(TIMELINE_SCALE)) { - TranslateTimeline timeline; - float timelineScale = 1; - if (timelineName.Equals(TIMELINE_SCALE)) - timeline = new ScaleTimeline(values.Count); - else { - timeline = new TranslateTimeline(values.Count); - timelineScale = Scale; - } - timeline.BoneIndex = boneIndex; + } else if (timelineName.Equals(TIMELINE_TRANSLATE) || timelineName.Equals(TIMELINE_SCALE)) { + TranslateTimeline timeline; + float timelineScale = 1; + if (timelineName.Equals(TIMELINE_SCALE)) + timeline = new ScaleTimeline(values.Count); + else { + timeline = new TranslateTimeline(values.Count); + timelineScale = Scale; + } + timeline.BoneIndex = boneIndex; - int frameIndex = 0; - foreach (Dictionary valueMap in values) { - float time = (float)valueMap["time"]; - float x = valueMap.ContainsKey("x") ? (float)valueMap["x"] : 0; - float y = valueMap.ContainsKey("y") ? (float)valueMap["y"] : 0; - timeline.SetFrame(frameIndex, time, (float)x * timelineScale, (float)y * timelineScale); - ReadCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.Add(timeline); - duration = Math.Max(duration, timeline.Frames[timeline.FrameCount * 3 - 3]); + int frameIndex = 0; + foreach (Dictionary valueMap in values) { + float time = (float)valueMap["time"]; + float x = valueMap.ContainsKey("x") ? (float)valueMap["x"] : 0; + float y = valueMap.ContainsKey("y") ? (float)valueMap["y"] : 0; + timeline.SetFrame(frameIndex, time, (float)x * timelineScale, (float)y * timelineScale); + ReadCurve(timeline, frameIndex, valueMap); + frameIndex++; + } + timelines.Add(timeline); + duration = Math.Max(duration, timeline.Frames[timeline.FrameCount * 3 - 3]); - } else - throw new Exception("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"); + } else + throw new Exception("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"); + } } } if (map.ContainsKey("slots")) { - Dictionary slotsMap = (Dictionary)map["slots"]; + var slotsMap = (Dictionary)map["slots"]; foreach (KeyValuePair entry in slotsMap) { String slotName = entry.Key; int slotIndex = skeletonData.FindSlotIndex(slotName); - Dictionary timelineMap = (Dictionary)entry.Value; + var timelineMap = (Dictionary)entry.Value; foreach (KeyValuePair timelineEntry in timelineMap) { - List values = (List)timelineEntry.Value; + var values = (List)timelineEntry.Value; String timelineName = (String)timelineEntry.Key; if (timelineName.Equals(TIMELINE_COLOR)) { ColorTimeline timeline = new ColorTimeline(values.Count);