diff options
Diffstat (limited to 'src')
41 files changed, 31 insertions, 1651 deletions
diff --git a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs index b52529a6..83638e10 100644 --- a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs +++ b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs @@ -135,11 +135,6 @@ namespace StardewModdingApi.Installer /// </remarks> public void Run(string[] args) { -#if SMAPI_1_x - bool installArg = false; - bool uninstallArg = false; - string gamePathArg = null; -#else /**** ** read command-line arguments ****/ @@ -160,7 +155,6 @@ namespace StardewModdingApi.Installer if (pathIndex >= 1 && args.Length >= pathIndex) gamePathArg = args[pathIndex]; } -#endif /**** ** collect details diff --git a/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs b/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs index fc84ca29..7a81c68c 100644 --- a/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs +++ b/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs @@ -141,7 +141,7 @@ namespace StardewModdingAPI.Tests.Core { // arrange Mock<IModMetadata> mock = this.GetMetadata("Mod A", new string[0], allowStatusChange: true); - this.SetupMetadataForValidation(mock, new ModCompatibility { Compatibility = ModCompatibilityType.AssumeBroken, UpperVersion = new SemanticVersion("1.0"), UpdateUrls = new[] { "http://example.org" }}); + this.SetupMetadataForValidation(mock, new ModCompatibility { Compatibility = ModCompatibilityType.AssumeBroken, UpperVersion = new SemanticVersion("1.0"), UpdateUrls = new[] { "http://example.org" } }); // act new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0")); @@ -179,7 +179,6 @@ namespace StardewModdingAPI.Tests.Core mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "The validation did not fail the metadata."); } -#if !SMAPI_1_x [Test(Description = "Assert that validation fails when multiple mods have the same unique ID.")] public void ValidateManifests_DuplicateUniqueID_Fails() { @@ -197,7 +196,6 @@ namespace StardewModdingAPI.Tests.Core modA.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "The validation did not fail the first mod with a unique ID."); modB.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "The validation did not fail the second mod with a unique ID."); } -#endif [Test(Description = "Assert that validation fails when the manifest references a DLL that does not exist.")] public void ValidateManifests_Valid_Passes() @@ -423,7 +421,6 @@ namespace StardewModdingAPI.Tests.Core Assert.AreSame(modB.Object, mods[1], "The load order is incorrect: mod B should be second since it needs mod A."); } -#if !SMAPI_1_x [Test(Description = "Assert that optional dependencies are sorted correctly if present.")] public void ProcessDependencies_IfOptional() { @@ -455,7 +452,6 @@ namespace StardewModdingAPI.Tests.Core Assert.AreEqual(1, mods.Length, 0, "Expected to get the same number of mods input."); Assert.AreSame(modB.Object, mods[0], "The load order is incorrect: mod B should be first since it's the only mod."); } -#endif /********* diff --git a/src/StardewModdingAPI.Tests/Core/TranslationTests.cs b/src/StardewModdingAPI.Tests/Core/TranslationTests.cs index 8511e765..63404a41 100644 --- a/src/StardewModdingAPI.Tests/Core/TranslationTests.cs +++ b/src/StardewModdingAPI.Tests/Core/TranslationTests.cs @@ -1,8 +1,7 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using NUnit.Framework; -using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.ModHelpers; using StardewValley; diff --git a/src/StardewModdingAPI/Command.cs b/src/StardewModdingAPI/Command.cs deleted file mode 100644 index 76c85287..00000000 --- a/src/StardewModdingAPI/Command.cs +++ /dev/null @@ -1,159 +0,0 @@ -#if SMAPI_1_x -using System; -using System.Collections.Generic; -using StardewModdingAPI.Events; -using StardewModdingAPI.Framework; - -namespace StardewModdingAPI -{ - /// <summary>A command that can be submitted through the SMAPI console to interact with SMAPI.</summary> - [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ConsoleCommands))] - public class Command - { - /********* - ** Properties - *********/ - /// <summary>The commands registered with SMAPI.</summary> - private static readonly IDictionary<string, Command> LegacyCommands = new Dictionary<string, Command>(StringComparer.InvariantCultureIgnoreCase); - - /// <summary>Manages console commands.</summary> - private static CommandManager CommandManager; - - /// <summary>Manages deprecation warnings.</summary> - private static DeprecationManager DeprecationManager; - - /// <summary>Tracks the installed mods.</summary> - private static ModRegistry ModRegistry; - - - /********* - ** Accessors - *********/ - /// <summary>The event raised when this command is submitted through the console.</summary> - public event EventHandler<EventArgsCommand> CommandFired; - - /**** - ** Command - ****/ - /// <summary>The name of the command.</summary> - public string CommandName; - - /// <summary>A human-readable description of what the command does.</summary> - public string CommandDesc; - - /// <summary>A human-readable list of accepted arguments.</summary> - public string[] CommandArgs; - - /// <summary>The actual submitted argument values.</summary> - public string[] CalledArgs; - - - /********* - ** Public methods - *********/ - /**** - ** Command - ****/ - /// <summary>Injects types required for backwards compatibility.</summary> - /// <param name="commandManager">Manages console commands.</param> - /// <param name="deprecationManager">Manages deprecation warnings.</param> - /// <param name="modRegistry">Tracks the installed mods.</param> - internal static void Shim(CommandManager commandManager, DeprecationManager deprecationManager, ModRegistry modRegistry) - { - Command.CommandManager = commandManager; - Command.DeprecationManager = deprecationManager; - Command.ModRegistry = modRegistry; - } - - /// <summary>Construct an instance.</summary> - /// <param name="name">The name of the command.</param> - /// <param name="description">A human-readable description of what the command does.</param> - /// <param name="args">A human-readable list of accepted arguments.</param> - public Command(string name, string description, string[] args = null) - { - this.CommandName = name; - this.CommandDesc = description; - if (args == null) - args = new string[0]; - this.CommandArgs = args; - } - - /// <summary>Trigger this command.</summary> - public void Fire() - { - if (this.CommandFired == null) - throw new InvalidOperationException($"Can't run command '{this.CommandName}' because it has no registered handler."); - this.CommandFired.Invoke(this, new EventArgsCommand(this)); - } - - - /**** - ** SMAPI - ****/ - /// <summary>Parse a command string and invoke it if valid.</summary> - /// <param name="input">The command to run, including the command name and any arguments.</param> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - public static void CallCommand(string input, IMonitor monitor) - { - Command.DeprecationManager.Warn("Command.CallCommand", "1.9", DeprecationLevel.PendingRemoval); - Command.CommandManager.Trigger(input); - } - - /// <summary>Register a command with SMAPI.</summary> - /// <param name="name">The name of the command.</param> - /// <param name="description">A human-readable description of what the command does.</param> - /// <param name="args">A human-readable list of accepted arguments.</param> - public static Command RegisterCommand(string name, string description, string[] args = null) - { - name = name?.Trim().ToLower(); - - // raise deprecation warning - Command.DeprecationManager.Warn("Command.RegisterCommand", "1.9", DeprecationLevel.PendingRemoval); - - // validate - if (Command.LegacyCommands.ContainsKey(name)) - throw new InvalidOperationException($"The '{name}' command is already registered!"); - - // add command - string modName = Command.ModRegistry.GetModFromStack() ?? "<unknown mod>"; - string documentation = args?.Length > 0 - ? $"{description} - {string.Join(", ", args)}" - : description; - Command.CommandManager.Add(modName, name, documentation, Command.Fire); - - // add legacy command - Command command = new Command(name, description, args); - Command.LegacyCommands.Add(name, command); - return command; - } - - /// <summary>Find a command with the given name.</summary> - /// <param name="name">The command name to find.</param> - public static Command FindCommand(string name) - { - Command.DeprecationManager.Warn("Command.FindCommand", "1.9", DeprecationLevel.PendingRemoval); - if (name == null) - return null; - - Command command; - Command.LegacyCommands.TryGetValue(name.Trim(), out command); - return command; - } - - - /********* - ** Private methods - *********/ - /// <summary>Trigger this command.</summary> - /// <param name="name">The command name.</param> - /// <param name="args">The command arguments.</param> - private static void Fire(string name, string[] args) - { - Command command; - if (!Command.LegacyCommands.TryGetValue(name, out command)) - throw new InvalidOperationException($"Can't run command '{name}' because there's no such legacy command."); - command.Fire(); - } - } -} -#endif
\ No newline at end of file diff --git a/src/StardewModdingAPI/Config.cs b/src/StardewModdingAPI/Config.cs deleted file mode 100644 index 734c04e8..00000000 --- a/src/StardewModdingAPI/Config.cs +++ /dev/null @@ -1,188 +0,0 @@ -#if SMAPI_1_x -using System; -using System.IO; -using System.Linq; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using StardewModdingAPI.Framework; - -namespace StardewModdingAPI -{ - /// <summary>A dynamic configuration class for a mod.</summary> - [Obsolete("This base class is obsolete since SMAPI 1.0. See the latest project README for details.")] - public abstract class Config - { - /********* - ** Properties - *********/ - /// <summary>Manages deprecation warnings.</summary> - private static DeprecationManager DeprecationManager; - - - /********* - ** Accessors - *********/ - /// <summary>The full path to the configuration file.</summary> - [JsonIgnore] - public virtual string ConfigLocation { get; protected internal set; } - - /// <summary>The directory path containing the configuration file.</summary> - [JsonIgnore] - public virtual string ConfigDir => Path.GetDirectoryName(this.ConfigLocation); - - - /********* - ** Public methods - *********/ - /// <summary>Injects types required for backwards compatibility.</summary> - /// <param name="deprecationManager">Manages deprecation warnings.</param> - internal static void Shim(DeprecationManager deprecationManager) - { - Config.DeprecationManager = deprecationManager; - } - - /// <summary>Construct an instance of the config class.</summary> - /// <typeparam name="T">The config class type.</typeparam> - [Obsolete("This base class is obsolete since SMAPI 1.0. See the latest project README for details.")] - public virtual Config Instance<T>() where T : Config => Activator.CreateInstance<T>(); - - /// <summary>Load the config from the JSON file, saving it to disk if needed.</summary> - /// <typeparam name="T">The config class type.</typeparam> - [Obsolete("This base class is obsolete since SMAPI 1.0. See the latest project README for details.")] - public virtual T LoadConfig<T>() where T : Config - { - // validate - if (string.IsNullOrEmpty(this.ConfigLocation)) - { - Log.Error("A config tried to load without specifying a location on the disk."); - return null; - } - - // read or generate config - T returnValue; - if (!File.Exists(this.ConfigLocation)) - { - T config = this.GenerateDefaultConfig<T>(); - config.ConfigLocation = this.ConfigLocation; - returnValue = config; - } - else - { - try - { - T config = JsonConvert.DeserializeObject<T>(File.ReadAllText(this.ConfigLocation)); - config.ConfigLocation = this.ConfigLocation; - returnValue = config.UpdateConfig<T>(); - } - catch (Exception ex) - { - Log.Error($"Invalid JSON ({this.GetType().Name}): {this.ConfigLocation} \n{ex}"); - return this.GenerateDefaultConfig<T>(); - } - } - - returnValue.WriteConfig(); - return returnValue; - } - - /// <summary>Get the default config values.</summary> - [Obsolete("This base class is obsolete since SMAPI 1.0. See the latest project README for details.")] - public virtual T GenerateDefaultConfig<T>() where T : Config - { - return null; - } - - /// <summary>Get the current configuration with missing values defaulted.</summary> - /// <typeparam name="T">The config class type.</typeparam> - [Obsolete("This base class is obsolete since SMAPI 1.0. See the latest project README for details.")] - public virtual T UpdateConfig<T>() where T : Config - { - try - { - // get default + user config - JObject defaultConfig = JObject.FromObject(this.Instance<T>().GenerateDefaultConfig<T>()); - JObject currentConfig = JObject.FromObject(this); - defaultConfig.Merge(currentConfig, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace }); - - // cast json object to config - T config = defaultConfig.ToObject<T>(); - - // update location - config.ConfigLocation = this.ConfigLocation; - - return config; - } - catch (Exception ex) - { - Log.Error($"An error occured when updating a config: {ex}"); - return this as T; - } - } - - - /********* - ** Protected methods - *********/ - /// <summary>Construct an instance.</summary> - protected Config() - { - Config.DeprecationManager.Warn("the Config class", "1.0", DeprecationLevel.PendingRemoval); - Config.DeprecationManager.MarkWarned($"{nameof(Mod)}.{nameof(Mod.BaseConfigPath)}", "1.0"); // typically used to construct config, avoid redundant warnings - } - } - - /// <summary>Provides extension methods for <see cref="Config"/> classes.</summary> - [Obsolete("This base class is obsolete since SMAPI 1.0. See the latest project README for details.")] - public static class ConfigExtensions - { - /// <summary>Initialise the configuration. That includes loading, saving, and merging the config file and in memory at a default state. This method should not be used to reload or to resave a config. NOTE: You MUST set your config EQUAL to the return of this method!</summary> - /// <typeparam name="T">The config class type.</typeparam> - /// <param name="baseConfig">The base configuration to initialise.</param> - /// <param name="configLocation">The base configuration file path.</param> - [Obsolete("This base class is obsolete since SMAPI 1.0. See the latest project README for details.")] - public static T InitializeConfig<T>(this T baseConfig, string configLocation) where T : Config - { - if (baseConfig == null) - baseConfig = Activator.CreateInstance<T>(); - - if (string.IsNullOrEmpty(configLocation)) - { - Log.Error("A config tried to initialize without specifying a location on the disk."); - return null; - } - - baseConfig.ConfigLocation = configLocation; - return baseConfig.LoadConfig<T>(); - } - - /// <summary>Writes the configuration to the JSON file.</summary> - /// <typeparam name="T">The config class type.</typeparam> - /// <param name="baseConfig">The base configuration to initialise.</param> - [Obsolete("This base class is obsolete since SMAPI 1.0. See the latest project README for details.")] - public static void WriteConfig<T>(this T baseConfig) where T : Config - { - if (string.IsNullOrEmpty(baseConfig?.ConfigLocation) || string.IsNullOrEmpty(baseConfig.ConfigDir)) - { - Log.Error("A config attempted to save when it itself or it's location were null."); - return; - } - - string json = JsonConvert.SerializeObject(baseConfig, Formatting.Indented); - if (!Directory.Exists(baseConfig.ConfigDir)) - Directory.CreateDirectory(baseConfig.ConfigDir); - - if (!File.Exists(baseConfig.ConfigLocation) || !File.ReadAllText(baseConfig.ConfigLocation).SequenceEqual(json)) - File.WriteAllText(baseConfig.ConfigLocation, json); - } - - /// <summary>Rereads the JSON file and merges its values with a default config. NOTE: You MUST set your config EQUAL to the return of this method!</summary> - /// <typeparam name="T">The config class type.</typeparam> - /// <param name="baseConfig">The base configuration to initialise.</param> - [Obsolete("This base class is obsolete since SMAPI 1.0. See the latest project README for details.")] - public static T ReloadConfig<T>(this T baseConfig) where T : Config - { - return baseConfig.LoadConfig<T>(); - } - } -} -#endif
\ No newline at end of file diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs index 07647d2d..fc780f40 100644 --- a/src/StardewModdingAPI/Constants.cs +++ b/src/StardewModdingAPI/Constants.cs @@ -28,12 +28,7 @@ namespace StardewModdingAPI ** Public ****/ /// <summary>SMAPI's current semantic version.</summary> - public static ISemanticVersion ApiVersion { get; } = -#if SMAPI_1_x - new SemanticVersion(1, 15, 4); -#else - new SemanticVersion(2, 0, 0, $"alpha-{DateTime.UtcNow:yyyyMMddHHmm}"); -#endif + public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(2, 0, 0, $"alpha-{DateTime.UtcNow:yyyyMMddHHmm}"); /// <summary>The minimum supported version of Stardew Valley.</summary> public static ISemanticVersion MinimumGameVersion { get; } = new SemanticVersion("1.2.30"); diff --git a/src/StardewModdingAPI/Events/EventArgsCommand.cs b/src/StardewModdingAPI/Events/EventArgsCommand.cs deleted file mode 100644 index 35370139..00000000 --- a/src/StardewModdingAPI/Events/EventArgsCommand.cs +++ /dev/null @@ -1,28 +0,0 @@ -#if SMAPI_1_x -using System; - -namespace StardewModdingAPI.Events -{ - /// <summary>Event arguments for a <see cref="StardewModdingAPI.Command.CommandFired"/> event.</summary> - [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ConsoleCommands))] - public class EventArgsCommand : EventArgs - { - /********* - ** Accessors - *********/ - /// <summary>The triggered command.</summary> - public Command Command { get; } - - - /********* - ** Public methods - *********/ - /// <summary>Construct an instance.</summary> - /// <param name="command">The triggered command.</param> - public EventArgsCommand(Command command) - { - this.Command = command; - } - } -} -#endif
\ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs b/src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs deleted file mode 100644 index 4c359939..00000000 --- a/src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs +++ /dev/null @@ -1,33 +0,0 @@ -#if SMAPI_1_x -using System; -using SFarmer = StardewValley.Farmer; - -namespace StardewModdingAPI.Events -{ - /// <summary>Event arguments for a <see cref="PlayerEvents.FarmerChanged"/> event.</summary> - public class EventArgsFarmerChanged : EventArgs - { - /********* - ** Accessors - *********/ - /// <summary>The previous player character.</summary> - public SFarmer NewFarmer { get; } - - /// <summary>The new player character.</summary> - public SFarmer PriorFarmer { get; } - - - /********* - ** Public methods - *********/ - /// <summary>Construct an instance.</summary> - /// <param name="priorFarmer">The previous player character.</param> - /// <param name="newFarmer">The new player character.</param> - public EventArgsFarmerChanged(SFarmer priorFarmer, SFarmer newFarmer) - { - this.PriorFarmer = priorFarmer; - this.NewFarmer = newFarmer; - } - } -} -#endif
\ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsInput.cs b/src/StardewModdingAPI/Events/EventArgsInput.cs index 31368555..66cb19f2 100644 --- a/src/StardewModdingAPI/Events/EventArgsInput.cs +++ b/src/StardewModdingAPI/Events/EventArgsInput.cs @@ -1,4 +1,3 @@ -#if !SMAPI_1_x using System; using System.Linq; using Microsoft.Xna.Framework; @@ -123,4 +122,3 @@ namespace StardewModdingAPI.Events } } } -#endif diff --git a/src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs b/src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs deleted file mode 100644 index 688b4b3d..00000000 --- a/src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs +++ /dev/null @@ -1,27 +0,0 @@ -#if SMAPI_1_x -using System; - -namespace StardewModdingAPI.Events -{ - /// <summary>Event arguments for a <see cref="PlayerEvents.LoadedGame"/> event.</summary> - public class EventArgsLoadedGameChanged : EventArgs - { - /********* - ** Accessors - *********/ - /// <summary>Whether the save has been loaded. This is always true.</summary> - public bool LoadedGame { get; } - - - /********* - ** Public methods - *********/ - /// <summary>Construct an instance.</summary> - /// <param name="loaded">Whether the save has been loaded. This is always true.</param> - public EventArgsLoadedGameChanged(bool loaded) - { - this.LoadedGame = loaded; - } - } -} -#endif
\ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsNewDay.cs b/src/StardewModdingAPI/Events/EventArgsNewDay.cs deleted file mode 100644 index b8cbe9e3..00000000 --- a/src/StardewModdingAPI/Events/EventArgsNewDay.cs +++ /dev/null @@ -1,37 +0,0 @@ -#if SMAPI_1_x -using System; - -namespace StardewModdingAPI.Events -{ - /// <summary>Event arguments for a <see cref="TimeEvents.OnNewDay"/> event.</summary> - public class EventArgsNewDay : EventArgs - { - /********* - ** Accessors - *********/ - /// <summary>The previous day value.</summary> - public int PreviousDay { get; } - - /// <summary>The current day value.</summary> - public int CurrentDay { get; } - - /// <summary>Whether the game just started the transition (<c>true</c>) or finished it (<c>false</c>).</summary> - public bool IsNewDay { get; } - - - /********* - ** Public methods - *********/ - /// <summary>Construct an instance.</summary> - /// <param name="priorDay">The previous day value.</param> - /// <param name="newDay">The current day value.</param> - /// <param name="isTransitioning">Whether the game just started the transition (<c>true</c>) or finished it (<c>false</c>).</param> - public EventArgsNewDay(int priorDay, int newDay, bool isTransitioning) - { - this.PreviousDay = priorDay; - this.CurrentDay = newDay; - this.IsNewDay = isTransitioning; - } - } -} -#endif
\ No newline at end of file diff --git a/src/StardewModdingAPI/Events/EventArgsStringChanged.cs b/src/StardewMo |
