/// <summary>Tries to load a texture given the <see cref="IContentSource"/>, the path to the texture, the list of source names for it, and the good type.</summary> private static bool TryLoadTextureProvider(IContentSource contentSource, string imagePath, List <string> source, ArtisanGood good, IMonitor monitor, out ArtisanGoodTextureProvider provider) { provider = null; if (imagePath == null) { return(false); } IManifest manifest = contentSource.GetManifest(); if (source == null || source.Count == 0 || source.Any(item => item == null)) { monitor.Log($"Couldn't load {good} from {manifest.Name} ({manifest.UniqueID}) because it has an invalid source list ({artisanGoodToSourceType[good]}).", LogLevel.Warn); monitor.Log($"{artisanGoodToSourceType[good]} must not be null, must not be empty, and cannot have null items inside it.", LogLevel.Warn); } else { try { provider = new ArtisanGoodTextureProvider(contentSource.Load <Texture2D>(imagePath), source, good); return(true); } catch (Exception) { monitor.Log($"Couldn't load {good} from {manifest.Name} ({manifest.UniqueID}) because the {good} texture file path is invalid ({imagePath}).", LogLevel.Warn); } } return(false); }
public T Load <T>(IContentSource contentSource) { switch (this.Source) { case ContentSource.GameContent: return(Game1.content.Load <T>(this.Path)); case ContentSource.ModFolder: return(contentSource.Load <T>(this.Path)); default: throw new InvalidOperationException($"Could not load from content source: {this.Source}"); } }
private ISprite CreateSprite(IContentSource contentSource, ContentPackDataInfo source, string key, ItemData objectData) { // TODO: Create each possible sprite (in the case of tokens and conditional values) // Try to get the sprite location if (!(objectData.Texture is string spriteLocation)) { throw new Exception($"{key} must have a valid sprite location."); } // Try to load the sprite spriteLocation = Path.Combine(source.Directory, spriteLocation); if (!(contentSource.Load <Texture2D>(spriteLocation) is Texture2D spriteTexture)) { throw new Exception($"{key}'s sprite location is invalid: {spriteLocation}"); } return(this._api.Items.CreateSprite(spriteTexture, objectData.FromArea)); }