diff --git a/SpriteLibrary/SpriteDatabase.cs b/SpriteLibrary/SpriteDatabase.cs index f0d7357..f253b48 100644 --- a/SpriteLibrary/SpriteDatabase.cs +++ b/SpriteLibrary/SpriteDatabase.cs @@ -123,6 +123,10 @@ namespace SpriteLibrary SpriteInfoList = new List(); //make an empty one so things do not explode. } + /// + /// Return a list of the SpriteNames that this Database knows how to create. + /// + /// A list of strings, each one is the name of a sprite public List SpriteNames() { List theNames = new List(); @@ -141,6 +145,11 @@ namespace SpriteLibrary return false; } + /// + /// Open a Sprite Edit Window. This window does not let you draw a sprite. What it does is to help + /// you define your sprites and makes the process of using Sprites in your program a lot easier. + /// + /// public void OpenEditWindow(int FirstItemIndex=-1) { SpriteEntryForm SEF = new SpriteEntryForm(this, SpriteInfoList, SnapGridSize); @@ -152,6 +161,19 @@ namespace SpriteLibrary #endregion #region General Functions + /// + /// This function returns an image from the Properties.Resources. If we tell it to UseSmartImages, then + /// it caches the image in memory. This makes it a little faster to return. If you have a lot of sprites + /// to load, using this system can speed up things a fair bit. But, try to remember not to change the + /// image that this returns unless you duplicate it first. Otherwise you will end up changing the image + /// for all the other times you reference it. This is usualy a bad thing. + /// + /// The string name of the image. If your image is usually named + /// Properties.Resources.mySpriteImage, you will want to have "mySpriteImage" as the Name passed + /// to GetImageFromName + /// A parameter stating whether we should cache the image in memory + /// or simply retrieve it from the resource manager. + /// public Image GetImageFromName(string Name, bool UseSmartImages) { Image MyImage = null; @@ -181,7 +203,16 @@ namespace SpriteLibrary return MyImage; } - public Sprite SmartDuplicateSprite(SpriteController theController, string SpriteName, bool UseSmartImages = true) + /// + /// This code is mostly handled by the sprite controller. If the SpriteController has a SpriteDatabase + /// registered, then it will automatically ask the SpriteDatabase to create any sprite it does not already + /// have. + /// + /// The controller that will manage the newly created Sprite + /// The name of the sprite to look up and then create + /// Whether or not we should cache images to give a very small increase in speed + /// + internal Sprite SmartDuplicateSprite(SpriteController theController, string SpriteName, bool UseSmartImages = true) { Sprite DestSprite = theController.DuplicateSprite(SpriteName); if (DestSprite != null) return DestSprite; @@ -279,6 +310,15 @@ namespace SpriteLibrary } } + /// + /// This is a generic function which the SpriteDatabase uses. It does XML Serialization of most anything, + /// and generates an XML String. XML Serialization will take any public value of a public class and + /// make an XML entry for it. It is a very convienent way to save data. You can "Deserialize" the value + /// with the ReadFromXMLString function. + /// + /// The type of the item that you are trying to serialize + /// the variable you are trying to turn into XML + /// An XML string public static string WriteToXMLString(T toSerialize) { XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType()); @@ -289,6 +329,16 @@ namespace SpriteLibrary return textWriter.ToString(); } } + + /// + /// This is a generic function which the SpriteDatabase uses. It does XML Deserialization of most anything, + /// and generates an XML String. XML Serialization will take any public value of a public class and + /// make an XML entry for it. It is a very convienent way to save and retrieve data. You can "Serialize" the value + /// with the WriteToXMLString function. + /// + /// The type of the item that you are trying to deserialize + /// an XML string, of something you serialized previously + /// An object of type T public static T ReadFromXmlString(string toDeserialize) where T : new() { XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); @@ -296,6 +346,14 @@ namespace SpriteLibrary return (T)xmlSerializer.Deserialize(textReader); } + /// + /// This is an inefficient, but simple function to clone a class. It works by serializing an item + /// to a string, and then deserializing it into a class. The end result is that any value which is + /// publically visible is duplicated, but it is a completely separate class from the original. + /// + /// The type of the item to clone + /// The actual object to clone + /// A duplicate of the original public static T CloneByXMLSerializing(T ObjectToClone) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));