Explorar el Código

Removed use of Tuple, unsupported on WP XNA.
Made parsing floats not locale specific.

NathanSweet hace 12 años
padre
commit
977122f41c
Se han modificado 3 ficheros con 36 adiciones y 22 borrados
  1. 2 1
      spine-csharp/src/Json.cs
  2. 22 11
      spine-csharp/src/SkeletonJson.cs
  3. 12 10
      spine-csharp/src/Skin.cs

+ 2 - 1
spine-csharp/src/Json.cs

@@ -31,6 +31,7 @@ using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.IO;
 using System.IO;
 using System.Text;
 using System.Text;
+using System.Globalization;
  
  
 namespace Spine
 namespace Spine
 {
 {
@@ -296,7 +297,7 @@ namespace Spine
                 //}
                 //}
 
 
 					 float parsedFloat;
 					 float parsedFloat;
-					 float.TryParse(number, out parsedFloat);
+					 float.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out parsedFloat); 
 					 return parsedFloat;
 					 return parsedFloat;
             }
             }
  
  

+ 22 - 11
spine-csharp/src/SkeletonJson.cs

@@ -52,7 +52,8 @@ namespace Spine {
 		}
 		}
 
 
 		public SkeletonData readSkeletonData (String name, String json) {
 		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 skeletonData = new SkeletonData();
 			skeletonData.Name = name;
 			skeletonData.Name = name;
@@ -64,7 +65,8 @@ namespace Spine {
 				BoneData parent = null;
 				BoneData parent = null;
 				if (boneMap.ContainsKey("parent")) {
 				if (boneMap.ContainsKey("parent")) {
 					parent = skeletonData.FindBone((String)boneMap["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 boneData = new BoneData((String)boneMap["name"], parent);
 				boneData.Length = getFloat(boneMap, "length", 0) * Scale;
 				boneData.Length = getFloat(boneMap, "length", 0) * Scale;
@@ -83,7 +85,8 @@ namespace Spine {
 					String slotName = (String)slotMap["name"];
 					String slotName = (String)slotMap["name"];
 					String boneName = (String)slotMap["bone"];
 					String boneName = (String)slotMap["bone"];
 					BoneData boneData = skeletonData.FindBone(boneName);
 					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);
 					SlotData slotData = new SlotData(slotName, boneData);
 
 
 					if (slotMap.ContainsKey("color")) {
 					if (slotMap.ContainsKey("color")) {
@@ -94,7 +97,8 @@ namespace Spine {
 						slotData.A = toColor(color, 3);
 						slotData.A = toColor(color, 3);
 					}
 					}
 
 
-					slotData.AttachmentName = (String)slotMap["attachment"];
+					if (slotMap.ContainsKey("attachment"))
+						slotData.AttachmentName = (String)slotMap["attachment"];
 
 
 					skeletonData.AddSlot(slotData);
 					skeletonData.AddSlot(slotData);
 				}
 				}
@@ -113,7 +117,8 @@ namespace Spine {
 						}
 						}
 					}
 					}
 					skeletonData.AddSkin(skin);
 					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<String, Object> map) {
 		private Attachment readAttachment (String name, Dictionary<String, Object> map) {
-			if (map.ContainsKey("name")) name = (String)map["name"];
+			if (map.ContainsKey("name"))
+				name = (String)map["name"];
 
 
 			AttachmentType type = AttachmentType.region;
 			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);
 			Attachment attachment = attachmentLoader.NewAttachment(type, name);
 
 
 			if (attachment is RegionAttachment) {
 			if (attachment is RegionAttachment) {
@@ -155,12 +162,14 @@ namespace Spine {
 		}
 		}
 
 
 		private float getFloat (Dictionary<String, Object> map, String name, float defaultValue) {
 		private float getFloat (Dictionary<String, Object> map, String name, float defaultValue) {
-			if (!map.ContainsKey(name)) return (float)defaultValue;
+			if (!map.ContainsKey(name))
+				return (float)defaultValue;
 			return (float)map[name];
 			return (float)map[name];
 		}
 		}
 
 
 		public static float toColor (String hexString, int colorIndex) {
 		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;
 			return Convert.ToInt32(hexString.Substring(colorIndex * 2, 2), 16) / (float)255;
 		}
 		}
 
 
@@ -172,7 +181,8 @@ namespace Spine {
 			foreach (KeyValuePair<String, Object> entry in bonesMap) {
 			foreach (KeyValuePair<String, Object> entry in bonesMap) {
 				String boneName = entry.Key;
 				String boneName = entry.Key;
 				int boneIndex = skeletonData.FindBoneIndex(boneName);
 				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<String, Object> timelineMap = (Dictionary<String, Object>)entry.Value;
 				Dictionary<String, Object> timelineMap = (Dictionary<String, Object>)entry.Value;
 				foreach (KeyValuePair<String, Object> timelineEntry in timelineMap) {
 				foreach (KeyValuePair<String, Object> timelineEntry in timelineMap) {
@@ -268,7 +278,8 @@ namespace Spine {
 		}
 		}
 
 
 		private void readCurve (CurveTimeline timeline, int frameIndex, Dictionary<String, Object> valueMap) {
 		private void readCurve (CurveTimeline timeline, int frameIndex, Dictionary<String, Object> valueMap) {
-			if (!valueMap.ContainsKey("curve")) return;
+			if (!valueMap.ContainsKey("curve"))
+				return;
 			Object curveObject = valueMap["curve"];
 			Object curveObject = valueMap["curve"];
 			if (curveObject.Equals("stepped"))
 			if (curveObject.Equals("stepped"))
 				timeline.SetStepped(frameIndex);
 				timeline.SetStepped(frameIndex);

+ 12 - 10
spine-csharp/src/Skin.cs

@@ -30,7 +30,7 @@ namespace Spine {
 	/** Stores attachments by slot index and attachment name. */
 	/** Stores attachments by slot index and attachment name. */
 	public class Skin {
 	public class Skin {
 		public String Name { get; private set; }
 		public String Name { get; private set; }
-		private Dictionary<Tuple<int, String>, Attachment> attachments = new Dictionary<Tuple<int, String>, Attachment>();
+		private Dictionary<KeyValuePair<int, String>, Attachment> attachments = new Dictionary<KeyValuePair<int, String>, Attachment>();
 
 
 		public Skin (String name) {
 		public Skin (String name) {
 			if (name == null) throw new ArgumentNullException("name cannot be null.");
 			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) {
 		public void AddAttachment (int slotIndex, String name, Attachment attachment) {
 			if (attachment == null) throw new ArgumentNullException("attachment cannot be null.");
 			if (attachment == null) throw new ArgumentNullException("attachment cannot be null.");
-			attachments.Add(Tuple.Create<int, String>(slotIndex, name), attachment);
+			attachments.Add(new KeyValuePair<int, String>(slotIndex, name), attachment);
 		}
 		}
 
 
 		/** @return May be null. */
 		/** @return May be null. */
 		public Attachment GetAttachment (int slotIndex, String name) {
 		public Attachment GetAttachment (int slotIndex, String name) {
-			return attachments[Tuple.Create<int, String>(slotIndex, name)];
+			KeyValuePair<int, String> key = new KeyValuePair<int, String>(slotIndex, name);
+			if (!attachments.ContainsKey(key)) return null;
+			return attachments[key];
 		}
 		}
 
 
 		public void FindNamesForSlot (int slotIndex, List<String> names) {
 		public void FindNamesForSlot (int slotIndex, List<String> names) {
 			if (names == null) throw new ArgumentNullException("names cannot be null.");
 			if (names == null) throw new ArgumentNullException("names cannot be null.");
-			foreach (Tuple<int, String> key in attachments.Keys)
-				if (key.Item1 == slotIndex) names.Add(key.Item2);
+			foreach (KeyValuePair<int, String> key in attachments.Keys)
+				if (key.Key == slotIndex) names.Add(key.Value);
 		}
 		}
 
 
 		public void FindAttachmentsForSlot (int slotIndex, List<Attachment> attachments) {
 		public void FindAttachmentsForSlot (int slotIndex, List<Attachment> attachments) {
 			if (attachments == null) throw new ArgumentNullException("attachments cannot be null.");
 			if (attachments == null) throw new ArgumentNullException("attachments cannot be null.");
-			foreach (KeyValuePair<Tuple<int, String>, Attachment> entry in this.attachments)
-				if (entry.Key.Item1 == slotIndex) attachments.Add(entry.Value);
+			foreach (KeyValuePair<KeyValuePair<int, String>, Attachment> entry in this.attachments)
+				if (entry.Key.Key == slotIndex) attachments.Add(entry.Value);
 		}
 		}
 
 
 		override public String ToString () {
 		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. */
 		/** Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached. */
 		internal void AttachAll (Skeleton skeleton, Skin oldSkin) {
 		internal void AttachAll (Skeleton skeleton, Skin oldSkin) {
-			foreach (KeyValuePair<Tuple<int, String>, Attachment> entry in oldSkin.attachments) {
-				int slotIndex = entry.Key.Item1;
+			foreach (KeyValuePair<KeyValuePair<int, String>, Attachment> entry in oldSkin.attachments) {
+				int slotIndex = entry.Key.Key;
 				Slot slot = skeleton.Slots[slotIndex];
 				Slot slot = skeleton.Slots[slotIndex];
 				if (slot.Attachment == entry.Value) {
 				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;
 					if (attachment != null) slot.Attachment = attachment;
 				}
 				}
 			}
 			}