mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
Removed use of Tuple, unsupported on WP XNA.
Made parsing floats not locale specific.
This commit is contained in:
parent
d66f211456
commit
977122f41c
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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<String, Object> 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<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];
|
||||
}
|
||||
|
||||
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<String, Object> 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<String, Object> timelineMap = (Dictionary<String, Object>)entry.Value;
|
||||
foreach (KeyValuePair<String, Object> timelineEntry in timelineMap) {
|
||||
@ -268,7 +278,8 @@ namespace Spine {
|
||||
}
|
||||
|
||||
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"];
|
||||
if (curveObject.Equals("stepped"))
|
||||
timeline.SetStepped(frameIndex);
|
||||
|
||||
@ -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<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) {
|
||||
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<int, String>(slotIndex, name), attachment);
|
||||
attachments.Add(new KeyValuePair<int, String>(slotIndex, name), attachment);
|
||||
}
|
||||
|
||||
/** @return May be null. */
|
||||
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) {
|
||||
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) {
|
||||
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 () {
|
||||
@ -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<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];
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user