using System.Reflection; using PkmnLib.Static.Libraries; namespace PkmnLib.Dynamic.ScriptHandling.Registry; /// /// Interface for plugins that provide resources. /// public interface IResourceProvider { /// /// The settings for the library. This is used to configure the library and its resources. /// LibrarySettings? Settings { get; } /// /// Gets the resource for the given type. This is used to load resources from the plugin. Returns null if the /// plugin does not provide the resource. /// IResourceResult? GetResource(ResourceFileType request); } /// /// Enum for the different types of resources that can be loaded. /// public enum ResourceFileType { /// /// Unknown type. This is used for errors and should not be used in normal code. /// Unknown, /// /// The type for the types of Pokémon. This includes the type effectiveness chart and the type names. /// Types, /// /// The type for the natures of Pokémon. This includes the nature names and the nature effects. /// Natures, /// /// The type for the moves of Pokémon. This includes the move names and the move effects. /// Moves, /// /// The type for the items of Pokémon. This includes the item names and the item effects. /// Items, /// /// The type for the abilities of Pokémon. This includes the ability names and the ability effects. /// Abilities, /// /// The type for the growth rates of Pokémon. This includes the growth rate names and the growth rate effects. /// GrowthRates, /// /// The type for the species of Pokémon. This includes the species names and the species effects. /// Species, } /// /// Interface for a resource result. This is used to load resources from the plugin. /// public interface IResourceResult { /// /// Opens the resource and returns a stream. This is used to load the resource from the plugin. /// Stream Open(); } /// /// Class for a resource result that is loaded from an embedded resource in an assembly. /// public class AssemblyResourceResult : IResourceResult { private readonly string _resourceName; private readonly Assembly _assembly; /// public AssemblyResourceResult(string resourceName, Assembly assembly) { _resourceName = resourceName; _assembly = assembly; } /// public Stream Open() => _assembly.GetManifestResourceStream(_resourceName) ?? throw new InvalidOperationException( $"Resource '{_resourceName}' not found in assembly '{_assembly.FullName}'."); }