using System; using System.Collections; using System.IO; namespace Strawberry { static public class Assets { static public Dictionary Sprites { get; private set; } static public Dictionary Fonts { get; private set; } static public void LoadAll() { Sprites = new Dictionary(); Load("Sprites", "*.ase*", Sprites); Fonts = new Dictionary(); Load("Fonts", "*.ttf", Fonts); } static public void DisposeAll() { DeleteDictionaryAndKeysAndItems!(Sprites); DeleteDictionaryAndKeysAndItems!(Fonts); Sprite.[Friend]Dispose(); } static private void Load(String directory, String wildcard, Dictionary putInto) where T : Asset { let root = scope String(Game.ContentRoot); root.Append(Path.DirectorySeparatorChar); root.Append(directory); if (Directory.Exists(root)) LoadDir(root, wildcard, putInto); else Calc.Log("Content/{0} folder does not exist!", directory); } static private void LoadDir(String directory, String wildcard, Dictionary putInto) where T : Asset { //Recursive folder search for (let dir in Directory.EnumerateDirectories(directory)) { let path = scope String(); dir.GetFilePath(path); LoadDir(path, wildcard, putInto); } //Load files for (let file in Directory.EnumerateFiles(directory, wildcard)) { let path = scope String(); file.GetFilePath(path); let sprite = new [Friend]T(path); path.Remove(0, Game.ContentRoot.Length + 9); path.RemoveFromEnd(path.Length - path.IndexOf('.')); putInto.Add(new String(path), sprite); } } } }