From 977122f41cac3579752c9179b166806874611f7b Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sat, 13 Apr 2013 10:12:42 +0200 Subject: [PATCH] Removed use of Tuple, unsupported on WP XNA. Made parsing floats not locale specific. --- spine-csharp/src/Json.cs | 3 ++- spine-csharp/src/SkeletonJson.cs | 33 +++++++++++++++++++++----------- spine-csharp/src/Skin.cs | 22 +++++++++++---------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/spine-csharp/src/Json.cs b/spine-csharp/src/Json.cs index 25b67be9d..9fcbd3f3d 100644 --- a/spine-csharp/src/Json.cs +++ b/spine-csharp/src/Json.cs @@ -31,6 +31,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; +using System.Globalization; namespace Spine { @@ -296,7 +297,7 @@ namespace Spine //} float parsedFloat; - float.TryParse(number, out parsedFloat); + float.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out parsedFloat); return parsedFloat; } diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index fbec2c96e..97e60e0ca 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -52,7 +52,8 @@ namespace Spine { } public SkeletonData readSkeletonData (String name, String json) { - if (json == null) throw new ArgumentNullException("json cannot be null."); + if (json == null) + throw new ArgumentNullException("json cannot be null."); SkeletonData skeletonData = new SkeletonData(); skeletonData.Name = name; @@ -64,7 +65,8 @@ namespace Spine { 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 (parent == null) + throw new Exception("Parent bone not found: " + boneMap["parent"]); } BoneData boneData = new BoneData((String)boneMap["name"], parent); boneData.Length = getFloat(boneMap, "length", 0) * Scale; @@ -83,7 +85,8 @@ namespace Spine { String slotName = (String)slotMap["name"]; String boneName = (String)slotMap["bone"]; BoneData boneData = skeletonData.FindBone(boneName); - if (boneData == null) throw new Exception("Slot bone not found: " + boneName); + if (boneData == null) + throw new Exception("Slot bone not found: " + boneName); SlotData slotData = new SlotData(slotName, boneData); if (slotMap.ContainsKey("color")) { @@ -94,7 +97,8 @@ namespace Spine { slotData.A = toColor(color, 3); } - slotData.AttachmentName = (String)slotMap["attachment"]; + if (slotMap.ContainsKey("attachment")) + slotData.AttachmentName = (String)slotMap["attachment"]; skeletonData.AddSlot(slotData); } @@ -113,7 +117,8 @@ namespace Spine { } } skeletonData.AddSkin(skin); - if (skin.Name == "default") skeletonData.DefaultSkin = skin; + if (skin.Name == "default") + skeletonData.DefaultSkin = skin; } } @@ -133,10 +138,12 @@ namespace Spine { } private Attachment readAttachment (String name, Dictionary map) { - if (map.ContainsKey("name")) name = (String)map["name"]; + if (map.ContainsKey("name")) + name = (String)map["name"]; AttachmentType type = AttachmentType.region; - if (map.ContainsKey("type")) type = (AttachmentType)Enum.Parse(typeof(AttachmentType), (String)map["type"], false); + if (map.ContainsKey("type")) + type = (AttachmentType)Enum.Parse(typeof(AttachmentType), (String)map["type"], false); Attachment attachment = attachmentLoader.NewAttachment(type, name); if (attachment is RegionAttachment) { @@ -155,12 +162,14 @@ namespace Spine { } private float getFloat (Dictionary map, String name, float defaultValue) { - if (!map.ContainsKey(name)) return (float)defaultValue; + if (!map.ContainsKey(name)) + return (float)defaultValue; return (float)map[name]; } public static float toColor (String hexString, int colorIndex) { - if (hexString.Length != 8) throw new ArgumentException("Color hexidecimal length must be 8, recieved: " + hexString); + if (hexString.Length != 8) + throw new ArgumentException("Color hexidecimal length must be 8, recieved: " + hexString); return Convert.ToInt32(hexString.Substring(colorIndex * 2, 2), 16) / (float)255; } @@ -172,7 +181,8 @@ namespace Spine { 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 (boneIndex == -1) + throw new Exception("Bone not found: " + boneName); Dictionary timelineMap = (Dictionary)entry.Value; foreach (KeyValuePair timelineEntry in timelineMap) { @@ -268,7 +278,8 @@ namespace Spine { } private void readCurve (CurveTimeline timeline, int frameIndex, Dictionary valueMap) { - if (!valueMap.ContainsKey("curve")) return; + if (!valueMap.ContainsKey("curve")) + return; Object curveObject = valueMap["curve"]; if (curveObject.Equals("stepped")) timeline.SetStepped(frameIndex); diff --git a/spine-csharp/src/Skin.cs b/spine-csharp/src/Skin.cs index 730e48ac0..78df8ef03 100644 --- a/spine-csharp/src/Skin.cs +++ b/spine-csharp/src/Skin.cs @@ -30,7 +30,7 @@ namespace Spine { /** Stores attachments by slot index and attachment name. */ public class Skin { public String Name { get; private set; } - private Dictionary, Attachment> attachments = new Dictionary, Attachment>(); + private Dictionary, Attachment> attachments = new Dictionary, Attachment>(); public Skin (String name) { if (name == null) throw new ArgumentNullException("name cannot be null."); @@ -39,24 +39,26 @@ namespace Spine { public void AddAttachment (int slotIndex, String name, Attachment attachment) { if (attachment == null) throw new ArgumentNullException("attachment cannot be null."); - attachments.Add(Tuple.Create(slotIndex, name), attachment); + attachments.Add(new KeyValuePair(slotIndex, name), attachment); } /** @return May be null. */ public Attachment GetAttachment (int slotIndex, String name) { - return attachments[Tuple.Create(slotIndex, name)]; + KeyValuePair key = new KeyValuePair(slotIndex, name); + if (!attachments.ContainsKey(key)) return null; + return attachments[key]; } public void FindNamesForSlot (int slotIndex, List names) { if (names == null) throw new ArgumentNullException("names cannot be null."); - foreach (Tuple key in attachments.Keys) - if (key.Item1 == slotIndex) names.Add(key.Item2); + foreach (KeyValuePair key in attachments.Keys) + if (key.Key == slotIndex) names.Add(key.Value); } public void FindAttachmentsForSlot (int slotIndex, List attachments) { if (attachments == null) throw new ArgumentNullException("attachments cannot be null."); - foreach (KeyValuePair, Attachment> entry in this.attachments) - if (entry.Key.Item1 == slotIndex) attachments.Add(entry.Value); + foreach (KeyValuePair, Attachment> entry in this.attachments) + if (entry.Key.Key == slotIndex) attachments.Add(entry.Value); } override public String ToString () { @@ -65,11 +67,11 @@ namespace Spine { /** Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached. */ internal void AttachAll (Skeleton skeleton, Skin oldSkin) { - foreach (KeyValuePair, Attachment> entry in oldSkin.attachments) { - int slotIndex = entry.Key.Item1; + foreach (KeyValuePair, Attachment> entry in oldSkin.attachments) { + int slotIndex = entry.Key.Key; Slot slot = skeleton.Slots[slotIndex]; if (slot.Attachment == entry.Value) { - Attachment attachment = GetAttachment(slotIndex, entry.Key.Item2); + Attachment attachment = GetAttachment(slotIndex, entry.Key.Value); if (attachment != null) slot.Attachment = attachment; } }