diff options
-rw-r--r-- | release-notes.md | 7 | ||||
-rw-r--r-- | src/GlobalAssemblyInfo.cs | 4 | ||||
-rw-r--r-- | src/StardewModdingAPI.Tests/ModResolverTests.cs | 1 | ||||
-rw-r--r-- | src/StardewModdingAPI/Constants.cs | 2 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/IModMetadata.cs (renamed from src/StardewModdingAPI/Framework/ModLoading/IModMetadata.cs) | 10 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/ModHelper.cs | 7 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/ModLoading/ModMetadata.cs | 11 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/ModRegistry.cs | 14 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 27 | ||||
-rw-r--r-- | src/StardewModdingAPI/StardewModdingAPI.csproj | 2 |
10 files changed, 58 insertions, 27 deletions
diff --git a/release-notes.md b/release-notes.md index 641071e5..b7f5f1f7 100644 --- a/release-notes.md +++ b/release-notes.md @@ -10,6 +10,13 @@ For mod developers: images). --> +## 1.13.1 +See [log](https://github.com/Pathoschild/SMAPI/compare/1.13...1.13.1). + +For players: +* Fixed errors when loading a mod with no name or version. +* Fixed mods with no manifest `Name` field having no name (SMAPI will now shows their filename). + ## 1.13 See [log](https://github.com/Pathoschild/SMAPI/compare/1.12...1.13). diff --git a/src/GlobalAssemblyInfo.cs b/src/GlobalAssemblyInfo.cs index 06b99c67..93ff68ec 100644 --- a/src/GlobalAssemblyInfo.cs +++ b/src/GlobalAssemblyInfo.cs @@ -2,5 +2,5 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] -[assembly: AssemblyVersion("1.12.0.0")] -[assembly: AssemblyFileVersion("1.12.0.0")]
\ No newline at end of file +[assembly: AssemblyVersion("1.13.1.0")] +[assembly: AssemblyFileVersion("1.13.1.0")]
\ No newline at end of file diff --git a/src/StardewModdingAPI.Tests/ModResolverTests.cs b/src/StardewModdingAPI.Tests/ModResolverTests.cs index efa6fa06..8cf5a29e 100644 --- a/src/StardewModdingAPI.Tests/ModResolverTests.cs +++ b/src/StardewModdingAPI.Tests/ModResolverTests.cs @@ -5,6 +5,7 @@ using System.Linq; using Moq; using Newtonsoft.Json; using NUnit.Framework; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Models; using StardewModdingAPI.Framework.ModLoading; using StardewModdingAPI.Framework.Serialisation; diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs index 5e4759e9..1c60da82 100644 --- a/src/StardewModdingAPI/Constants.cs +++ b/src/StardewModdingAPI/Constants.cs @@ -33,7 +33,7 @@ namespace StardewModdingAPI ** Public ****/ /// <summary>SMAPI's current semantic version.</summary> - public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(1, 13, 0); + public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(1, 13, 1); /// <summary>The minimum supported version of Stardew Valley.</summary> public static ISemanticVersion MinimumGameVersion { get; } = new SemanticVersion("1.2.26"); diff --git a/src/StardewModdingAPI/Framework/ModLoading/IModMetadata.cs b/src/StardewModdingAPI/Framework/IModMetadata.cs index 3771ffdd..56ac25f1 100644 --- a/src/StardewModdingAPI/Framework/ModLoading/IModMetadata.cs +++ b/src/StardewModdingAPI/Framework/IModMetadata.cs @@ -1,6 +1,7 @@ using StardewModdingAPI.Framework.Models; +using StardewModdingAPI.Framework.ModLoading; -namespace StardewModdingAPI.Framework.ModLoading +namespace StardewModdingAPI.Framework { /// <summary>Metadata for a mod.</summary> internal interface IModMetadata @@ -26,6 +27,9 @@ namespace StardewModdingAPI.Framework.ModLoading /// <summary>The reason the metadata is invalid, if any.</summary> string Error { get; } + /// <summary>The mod instance (if it was loaded).</summary> + IMod Mod { get; } + /********* ** Public methods @@ -35,5 +39,9 @@ namespace StardewModdingAPI.Framework.ModLoading /// <param name="error">The reason the metadata is invalid, if any.</param> /// <returns>Return the instance for chaining.</returns> IModMetadata SetStatus(ModMetadataStatus status, string error = null); + + /// <summary>Set the mod instance.</summary> + /// <param name="mod">The mod instance to set.</param> + IModMetadata SetMod(IMod mod); } } diff --git a/src/StardewModdingAPI/Framework/ModHelper.cs b/src/StardewModdingAPI/Framework/ModHelper.cs index 7810148c..f939b83c 100644 --- a/src/StardewModdingAPI/Framework/ModHelper.cs +++ b/src/StardewModdingAPI/Framework/ModHelper.cs @@ -37,6 +37,7 @@ namespace StardewModdingAPI.Framework ** Public methods *********/ /// <summary>Construct an instance.</summary> + /// <param name="displayName">The mod's display name.</param> /// <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> @@ -46,7 +47,7 @@ namespace StardewModdingAPI.Framework /// <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) + public ModHelper(string displayName, IManifest manifest, string modDirectory, JsonHelper jsonHelper, IModRegistry modRegistry, CommandManager commandManager, SContentManager contentManager, IReflectionHelper reflection) { // validate if (string.IsNullOrWhiteSpace(modDirectory)) @@ -61,9 +62,9 @@ namespace StardewModdingAPI.Framework // initialise this.DirectoryPath = modDirectory; this.JsonHelper = jsonHelper; - this.Content = new ContentHelper(contentManager, modDirectory, manifest.Name); + this.Content = new ContentHelper(contentManager, modDirectory, displayName); this.ModRegistry = modRegistry; - this.ConsoleCommands = new CommandHelper(manifest.Name, commandManager); + this.ConsoleCommands = new CommandHelper(displayName, commandManager); this.Reflection = reflection; } diff --git a/src/StardewModdingAPI/Framework/ModLoading/ModMetadata.cs b/src/StardewModdingAPI/Framework/ModLoading/ModMetadata.cs index 7b25e090..ab590e10 100644 --- a/src/StardewModdingAPI/Framework/ModLoading/ModMetadata.cs +++ b/src/StardewModdingAPI/Framework/ModLoading/ModMetadata.cs @@ -26,6 +26,9 @@ namespace StardewModdingAPI.Framework.ModLoading /// <summary>The reason the metadata is invalid, if any.</summary> public string Error { get; private set; } + /// <summary>The mod instance (if it was loaded).</summary> + public IMod Mod { get; private set; } + /********* ** Public methods @@ -53,5 +56,13 @@ namespace StardewModdingAPI.Framework.ModLoading this.Error = error; return this; } + + /// <summary>Set the mod instance.</summary> + /// <param name="mod">The mod instance to set.</param> + public IModMetadata SetMod(IMod mod) + { + this.Mod = mod; + return this; + } } } diff --git a/src/StardewModdingAPI/Framework/ModRegistry.cs b/src/StardewModdingAPI/Framework/ModRegistry.cs index 3899aa3f..62063fbd 100644 --- a/src/StardewModdingAPI/Framework/ModRegistry.cs +++ b/src/StardewModdingAPI/Framework/ModRegistry.cs @@ -13,7 +13,7 @@ namespace StardewModdingAPI.Framework ** Properties *********/ /// <summary>The registered mod data.</summary> - private readonly List<IMod> Mods = new List<IMod>(); + private readonly List<IModMetadata> Mods = new List<IModMetadata>(); /// <summary>The friendly mod names treated as deprecation warning sources (assembly full name => mod name).</summary> private readonly IDictionary<string, string> ModNamesByAssembly = new Dictionary<string, string>(); @@ -28,7 +28,7 @@ namespace StardewModdingAPI.Framework /// <summary>Get metadata for all loaded mods.</summary> public IEnumerable<IManifest> GetAll() { - return this.Mods.Select(p => p.ModManifest); + return this.Mods.Select(p => p.Manifest); } /// <summary>Get metadata for a loaded mod.</summary> @@ -50,15 +50,15 @@ namespace StardewModdingAPI.Framework ** Internal methods ****/ /// <summary>Register a mod as a possible source of deprecation warnings.</summary> - /// <param name="mod">The mod instance.</param> - public void Add(IMod mod) + /// <param name="metadata">The mod metadata.</param> + public void Add(IModMetadata metadata) { - this.Mods.Add(mod); - this.ModNamesByAssembly[mod.GetType().Assembly.FullName] = mod.ModManifest.Name; + this.Mods.Add(metadata); + this.ModNamesByAssembly[metadata.Mod.GetType().Assembly.FullName] = metadata.DisplayName; } /// <summary>Get all enabled mods.</summary> - public IEnumerable<IMod> GetMods() + public IEnumerable<IModMetadata> GetMods() { return (from mod in this.Mods select mod); } diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 3a7cb9ce..06523144 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -237,15 +237,15 @@ namespace StardewModdingAPI this.IsDisposed = true; // dispose mod data - foreach (IMod mod in this.ModRegistry.GetMods()) + foreach (IModMetadata mod in this.ModRegistry.GetMods()) { try { - (mod as IDisposable)?.Dispose(); + (mod.Mod as IDisposable)?.Dispose(); } catch (Exception ex) { - this.Monitor.Log($"The {mod.ModManifest.Name} mod failed during disposal: {ex.GetLogSummary()}.", LogLevel.Warn); + this.Monitor.Log($"The {mod.DisplayName} mod failed during disposal: {ex.GetLogSummary()}.", LogLevel.Warn); } } @@ -330,13 +330,13 @@ namespace StardewModdingAPI if (string.IsNullOrWhiteSpace(mod.Manifest.Name)) missingFields.Add(nameof(IManifest.Name)); - if (mod.Manifest.Version.ToString() == "0.0") + if (mod.Manifest.Version == null || mod.Manifest.Version.ToString() == "0.0") missingFields.Add(nameof(IManifest.Version)); if (string.IsNullOrWhiteSpace(mod.Manifest.UniqueID)) missingFields.Add(nameof(IManifest.UniqueID)); if (missingFields.Any()) - deprecationWarnings.Add(() => this.Monitor.Log($"{mod.Manifest.Name} is missing some manifest fields ({string.Join(", ", missingFields)}) which will be required in an upcoming SMAPI version.", LogLevel.Warn)); + deprecationWarnings.Add(() => this.Monitor.Log($"{mod.DisplayName} is missing some manifest fields ({string.Join(", ", missingFields)}) which will be required in an upcoming SMAPI version.", LogLevel.Warn)); } // per-save directories @@ -580,14 +580,15 @@ namespace StardewModdingAPI // inject data mod.ModManifest = manifest; - mod.Helper = new ModHelper(manifest, metadata.DirectoryPath, jsonHelper, this.ModRegistry, this.CommandManager, contentManager, this.Reflection); - mod.Monitor = this.GetSecondaryMonitor(manifest.Name); + mod.Helper = new ModHelper(metadata.DisplayName, manifest, metadata.DirectoryPath, jsonHelper, this.ModRegistry, this.CommandManager, contentManager, this.Reflection); + mod.Monitor = this.GetSecondaryMonitor(metadata.DisplayName); mod.PathOnDisk = metadata.DirectoryPath; // track mod - this.ModRegistry.Add(mod); + metadata.SetMod(mod); + this.ModRegistry.Add(metadata); modsLoaded += 1; - this.Monitor.Log($"Loaded {manifest.Name} by {manifest.Author}, v{manifest.Version} | {manifest.Description}", LogLevel.Info); + this.Monitor.Log($"Loaded {metadata.DisplayName} by {manifest.Author}, v{manifest.Version} | {manifest.Description}", LogLevel.Info); } catch (Exception ex) { @@ -596,21 +597,23 @@ namespace StardewModdingAPI } // initialise loaded mods - foreach (IMod mod in this.ModRegistry.GetMods()) + foreach (IModMetadata metadata in this.ModRegistry.GetMods()) { try { + IMod mod = metadata.Mod; + // call entry methods (mod as Mod)?.Entry(); // deprecated since 1.0 mod.Entry(mod.Helper); // raise deprecation warning for old Entry() methods if (this.DeprecationManager.IsVirtualMethodImplemented(mod.GetType(), typeof(Mod), nameof(Mod.Entry), new[] { typeof(object[]) })) - deprecationWarnings.Add(() => this.DeprecationManager.Warn(mod.ModManifest.Name, $"{nameof(Mod)}.{nameof(Mod.Entry)}(object[]) instead of {nameof(Mod)}.{nameof(Mod.Entry)}({nameof(IModHelper)})", "1.0", DeprecationLevel.Info)); + deprecationWarnings.Add(() => this.DeprecationManager.Warn(metadata.DisplayName, $"{nameof(Mod)}.{nameof(Mod.Entry)}(object[]) instead of {nameof(Mod)}.{nameof(Mod.Entry)}({nameof(IModHelper)})", "1.0", DeprecationLevel.Info)); } catch (Exception ex) { - this.Monitor.Log($"The {mod.ModManifest.Name} mod failed on entry initialisation. It will still be loaded, but may not function correctly.\n{ex.GetLogSummary()}", LogLevel.Warn); + this.Monitor.Log($"The {metadata.DisplayName} mod failed on entry initialisation. It will still be loaded, but may not function correctly.\n{ex.GetLogSummary()}", LogLevel.Warn); } } diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 60171493..d8bfd473 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -122,7 +122,7 @@ <Compile Include="Events\GameEvents.cs" /> <Compile Include="Events\GraphicsEvents.cs" /> <Compile Include="Framework\Countdown.cs" /> - <Compile Include="Framework\ModLoading\IModMetadata.cs" /> + <Compile Include="Framework\IModMetadata.cs" /> <Compile Include="Framework\ModLoading\InvalidModStateException.cs" /> <Compile Include="Framework\ModLoading\ModDependencyStatus.cs" /> <Compile Include="Framework\ModLoading\ModMetadataStatus.cs" /> |