/// <summary>Get a new content manager which defers loading to the content core.</summary> /// <param name="name">A name for the mod manager. Not guaranteed to be unique.</param> /// <param name="isModFolder">Whether this content manager is wrapped around a mod folder.</param> /// <param name="rootDirectory">The root directory to search for content (or <c>null</c>. for the default)</param> public SContentManager CreateContentManager(string name, bool isModFolder, string rootDirectory = null) { SContentManager manager = new SContentManager(name, this.MainContentManager.ServiceProvider, rootDirectory ?? this.MainContentManager.RootDirectory, this.MainContentManager.CurrentCulture, this, this.Monitor, this.Reflection, this.OnDisposing, isModFolder); this.ContentManagers.Add(manager); return(manager); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="contentManager">SMAPI's underlying content manager.</param> /// <param name="modFolderPath">The absolute path to the mod folder.</param> /// <param name="modName">The friendly mod name for use in errors.</param> public ContentHelper(SContentManager contentManager, string modFolderPath, string modName) { this.ContentManager = contentManager; this.ModFolderPath = modFolderPath; this.ModName = modName; this.ModFolderPathFromContent = this.GetRelativePath(contentManager.FullRootDirectory, modFolderPath); }
/********* ** Private methods *********/ /// <summary>A callback invoked when a content manager is disposed.</summary> /// <param name="contentManager">The content manager being disposed.</param> private void OnDisposing(SContentManager contentManager) { if (this.IsDisposed) { return; } this.ContentManagers.Remove(contentManager); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="manifest">The manifest for the associated mod.</param> /// <param name="modDirectory">The full path to the mod's folder.</param> /// <param name="jsonHelper">Encapsulate SMAPI's JSON parsing.</param> /// <param name="modRegistry">Metadata about loaded mods.</param> /// <param name="commandManager">Manages console commands.</param> /// <param name="contentManager">The content manager which loads content assets.</param> /// <param name="reflection">Simplifies access to private game code.</param> /// <exception cref="ArgumentNullException">An argument is null or empty.</exception> /// <exception cref="InvalidOperationException">The <paramref name="modDirectory"/> path does not exist on disk.</exception> public ModHelper(IManifest manifest, string modDirectory, JsonHelper jsonHelper, IModRegistry modRegistry, CommandManager commandManager, SContentManager contentManager, IReflectionHelper reflection) { // validate if (string.IsNullOrWhiteSpace(modDirectory)) { throw new ArgumentNullException(nameof(modDirectory)); } if (jsonHelper == null) { throw new ArgumentNullException(nameof(jsonHelper)); } if (modRegistry == null) { throw new ArgumentNullException(nameof(modRegistry)); } if (!Directory.Exists(modDirectory)) { throw new InvalidOperationException("The specified mod directory does not exist."); } // initialise this.DirectoryPath = modDirectory; this.JsonHelper = jsonHelper; this.Content = new ContentHelper(contentManager, modDirectory, manifest.Name); this.ModRegistry = modRegistry; this.ConsoleCommands = new CommandHelper(manifest.Name, commandManager); this.Reflection = reflection; }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="contentManager">SMAPI's underlying content manager.</param> /// <param name="name">The content manager's name for logs (if any).</param> public ContentManagerShim(SContentManager contentManager, string name) : base(contentManager.ServiceProvider, contentManager.RootDirectory, contentManager.CurrentCulture, contentManager.LanguageCodeOverride) { this.ContentManager = contentManager; this.Name = name; }