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 String ContentRoot { get; private set; } static public void LoadAll() { #if DEBUG ContentRoot = "../../../src/Content/"; #else ContentRoot = "Content"; #endif 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(ContentRoot); root.Append(Path.DirectorySeparatorChar); root.Append(directory); if (Directory.Exists(root)) LoadDir(root, root, wildcard, putInto); else Calc.Log("Create a Content/{0} folder to load {0}", directory); } static private void LoadDir(String rootDir, 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(rootDir, path, wildcard, putInto); } //Load files for (let file in Directory.EnumerateFiles(directory, wildcard)) { let path = scope String(); file.GetFilePath(path); let asset = new [Friend]T(path); path.Remove(0, rootDir.Length + 1); path.RemoveFromEnd(path.Length - path.IndexOf('.')); putInto.Add(new String(path), asset); } } } }