/// <summary> /// Adds an item in the dictionary from a Stream, and assign a key to it /// </summary> /// <param name="stream">The stream of the texture file. Stream is not disposed after use</param> /// <param name="keyName">The key used to refere to the item</param> public static void AddFromStream(Stream stream, string keyName) { // Check if the key already exists if (Content.ContainsKey(keyName)) { throw new ArgumentException("The given key name " + keyName + " already exists in the dictionary", "keyName"); } Content[keyName] = new GDContentItem(Texture2D.FromStream(device, stream), keyName); }
/// <summary> /// Returns a list of all the items currently stored in the GDContent class /// </summary> /// <returns>A list of all the items currently stored in the GDContent class</returns> public static GDContentItem[] GetAllItems() { GDContentItem[] items = new GDContentItem[Content.Count]; int i = 0; // Traverse the Dictionary that holds all the animation descriptors foreach (KeyValuePair <string, GDContentItem> k in Content) { items[i++] = k.Value; } return(items); }
/// <summary> /// Adds an item in the dictionary from a file, and assign a key to it /// </summary> /// <param name="fileName">The file name of the texture file</param> /// <param name="keyName">The key used to refere to the item. Leave blank for filename</param> public static void AddFromFile(string fileName, string keyName = "") { if (keyName == "") { keyName = fileName; } // Check if the key already exists if (Content.ContainsKey(keyName)) { throw new ArgumentException("The given key name " + keyName + " already exists in the dictionary", "keyName"); } FileStream f = File.OpenRead(fileName); Content[keyName] = new GDContentItem(Texture2D.FromStream(device, f), keyName); f.Close(); }