Cloning infrastructure and breaking up spriteInfo to be able to hold multiple animations for one sprite

This commit is contained in:
Tim Young 2017-09-15 20:16:26 -05:00
parent 72f1c3ac79
commit b881985b1b
2 changed files with 58 additions and 3 deletions

View File

@ -238,6 +238,37 @@ namespace SpriteLibrary
reader.Close();
}
}
public static string WriteToXMLString<T>(T toSerialize)
{
XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());
using (StringWriter textWriter = new StringWriter())
{
xmlSerializer.Serialize(textWriter, toSerialize);
return textWriter.ToString();
}
}
public static T ReadFromXmlString<T>(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>(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
}

View File

@ -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
/// <summary>
/// A generic cloning method that works when everything is public
/// </summary>
/// <returns></returns>
public AnimationInfo Clone()
{
return SpriteDatabase.CloneByXMLSerializing<AnimationInfo>(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<AnimationInfo> Animations = new List<AnimationInfo>();
/// <summary>
/// A generic cloning method that works when everything is public
/// </summary>
/// <returns></returns>
public SpriteInfo Clone()
{
return SpriteDatabase.CloneByXMLSerializing<SpriteInfo>(this);
}
}
}