diff --git a/SpriteLibrary/SpriteDatabase.cs b/SpriteLibrary/SpriteDatabase.cs index 0e89309..ba93380 100644 --- a/SpriteLibrary/SpriteDatabase.cs +++ b/SpriteLibrary/SpriteDatabase.cs @@ -238,6 +238,37 @@ namespace SpriteLibrary reader.Close(); } } + + public static string WriteToXMLString(T toSerialize) + { + XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType()); + + using (StringWriter textWriter = new StringWriter()) + { + xmlSerializer.Serialize(textWriter, toSerialize); + return textWriter.ToString(); + } + } + public static T ReadFromXmlString(string toDeserialize) where T : new() + { + XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); + using (StringReader textReader = new StringReader(toDeserialize)) + return (T)xmlSerializer.Deserialize(textReader); + } + + public static T CloneByXMLSerializing(T ObjectToClone) + { + XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); + string dest; + using (StringWriter textWriter = new StringWriter()) + { + xmlSerializer.Serialize(textWriter, ObjectToClone); + dest = textWriter.ToString(); + } + + using (StringReader textReader = new StringReader(dest)) + return (T)xmlSerializer.Deserialize(textReader); + } #endregion } diff --git a/SpriteLibrary/SpriteInfo.cs b/SpriteLibrary/SpriteInfo.cs index a727c30..89550b8 100644 --- a/SpriteLibrary/SpriteInfo.cs +++ b/SpriteLibrary/SpriteInfo.cs @@ -7,15 +7,39 @@ using System.Drawing; namespace SpriteLibrary { - internal class SpriteInfo + internal class AnimationInfo { - public string SpriteName = ""; public Point StartPoint = new Point(-1, -1); public string ImageName = ""; public int Width = -1; public int Height = -1; public int AnimSpeed = 200; - public int NumAnimations = 1; + public int NumFrames = 1; public int ViewPercent = 100; //The percent size of the sprite. 100 is full. 50 is half-size + + /// + /// A generic cloning method that works when everything is public + /// + /// + public AnimationInfo Clone() + { + return SpriteDatabase.CloneByXMLSerializing(this); + } + } + + internal class SpriteInfo + { + public string SpriteName = ""; + public int ViewPercent = 100; //The percent size of the sprite. 100 is full. 50 is half-size + public List Animations = new List(); + + /// + /// A generic cloning method that works when everything is public + /// + /// + public SpriteInfo Clone() + { + return SpriteDatabase.CloneByXMLSerializing(this); + } } }