using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CustomNPCFramework.Framework.Graphics { public class AssetManager { public List assets; public Dictionary paths; /// /// Basic constructor. /// public AssetManager() { this.assets = new List(); this.paths = new Dictionary(); } /// /// Default loading function from paths. /// public void loadAssets() { foreach(var path in this.paths) { string[] files= Directory.GetFiles(path.Value, "*.json"); foreach(var file in files) { AssetInfo info = AssetInfo.readFromJson(file); AssetSheet sheet = new AssetSheet(info,path.Value); this.assets.Add(sheet); } } } /// /// Add an asset to be handled from the asset manager. /// /// public void addAsset(AssetSheet asset) { this.assets.Add(asset); } /// /// Get an individual asset by its name. /// /// /// public AssetSheet getAssetByName(string s) { foreach(var v in assets) { if (v.assetInfo.name == s) return v; } return null; } /// /// Add a new path to the asset manager and create the directory for it. /// /// public void addPathCreateDirectory(KeyValuePair path) { this.addPath(path); string dir = Path.Combine(Class1.ModHelper.DirectoryPath, path.Value); if (!Directory.Exists(dir)) { Directory.CreateDirectory(Path.Combine(Class1.ModHelper.DirectoryPath, path.Value)); } } /// /// Add a path to the dictionary. /// /// private void addPath(KeyValuePair path) { this.paths.Add(path.Key, path.Value); } /// /// Create appropriate directories for the path. /// private void createDirectoriesFromPaths() { foreach(var v in paths) { Directory.CreateDirectory(Path.Combine(Class1.ModHelper.DirectoryPath,v.Value)); } } } }