diff options
Diffstat (limited to 'src/StardewModdingAPI')
35 files changed, 29 insertions, 1577 deletions
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/StardewModdingAPI/Events/EventArgsStringChanged.cs deleted file mode 100644 index f580a2ce..00000000 --- a/src/StardewModdingAPI/Events/EventArgsStringChanged.cs +++ /dev/null @@ -1,31 +0,0 @@ -#if SMAPI_1_x -using System; - -namespace StardewModdingAPI.Events -{ - /// <summary>Event arguments for a string field that changed value.</summary> - public class EventArgsStringChanged : EventArgs - { - /********* - ** Accessors - *********/ - /// <summary>The previous value.</summary> - public string NewString { get; } - - /// <summary>The current value.</summary> - public string PriorString { get; } - - /********* - ** Public methods - *********/ - /// <summary>Construct an instance.</summary> - /// <param name="priorString">The previous value.</param> - /// <param name="newString">The current value.</param> - public EventArgsStringChanged(string priorString, string newString) - { - this.NewString = newString; - this.PriorString = priorString; - } - } -} -#endif
\ No newline at end of file diff --git a/src/StardewModdingAPI/Events/GameEvents.cs b/src/StardewModdingAPI/Events/GameEvents.cs index deb71a86..b477376e 100644 --- a/src/StardewModdingAPI/Events/GameEvents.cs +++ b/src/StardewModdingAPI/Events/GameEvents.cs @@ -1,94 +1,17 @@ using System; -using System.Diagnostics.CodeAnalysis; using StardewModdingAPI.Framework; -#pragma warning disable 618 // Suppress obsolete-symbol errors in this file. Since several events are marked obsolete, this produces unnecessary warnings. namespace StardewModdingAPI.Events { /// <summary>Events raised when the game changes state.</summary> public static class GameEvents { /********* - ** Properties - *********/ -#if SMAPI_1_x - /// <summary>Manages deprecation warnings.</summary> - private static DeprecationManager DeprecationManager; - - /// <summary>The backing field for <see cref="Initialize"/>.</summary> - [SuppressMessage("ReSharper", "InconsistentNaming")] - private static event EventHandler _Initialize; - - /// <summary>The backing field for <see cref="LoadContent"/>.</summary> - [SuppressMessage("ReSharper", "InconsistentNaming")] - private static event EventHandler _LoadContent; - - /// <summary>The backing field for <see cref="GameLoaded"/>.</summary> - [SuppressMessage("ReSharper", "InconsistentNaming")] - private static event EventHandler _GameLoaded; - - /// <summary>The backing field for <see cref="FirstUpdateTick"/>.</summary> - [SuppressMessage("ReSharper", "InconsistentNaming")] - private static event EventHandler _FirstUpdateTick; -#endif - - - /********* ** Events *********/ /// <summary>Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called after <see cref="Microsoft.Xna.Framework.Game.Initialize"/>.</summary> internal static event EventHandler InitializeInternal; -#if SMAPI_1_x - /// <summary>Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called after <see cref="Microsoft.Xna.Framework.Game.Initialize"/>.</summary> - [Obsolete("The " + nameof(Mod) + "." + nameof(Mod.Entry) + " method is now called after the " + nameof(GameEvents.Initialize) + " event, so any contained logic can be done directly in " + nameof(Mod.Entry) + ".")] - public static event EventHandler Initialize - { - add - { - GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.Initialize)}", "1.10", DeprecationLevel.PendingRemoval); - GameEvents._Initialize += value; - } - remove => GameEvents._Initialize -= value; - } - - /// <summary>Raised before XNA loads or reloads graphics resources. Called during <see cref="Microsoft.Xna.Framework.Game.LoadContent"/>.</summary> - [Obsolete("The " + nameof(Mod) + "." + nameof(Mod.Entry) + " method is now called after the " + nameof(GameEvents.LoadContent) + " event, so any contained logic can be done directly in " + nameof(Mod.Entry) + ".")] - public static event EventHandler LoadContent - { - add - { - GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.LoadContent)}", "1.10", DeprecationLevel.PendingRemoval); - GameEvents._LoadContent += value; - } - remove => GameEvents._LoadContent -= value; - } - - /// <summary>Raised during launch after configuring Stardew Valley, loading it into memory, and opening the game window. The window is still blank by this point.</summary> - [Obsolete("The " + nameof(Mod) + "." + nameof(Mod.Entry) + " method is now called after the game loads, so any contained logic can be done directly in " + nameof(Mod.Entry) + ".")] - public static event EventHandler GameLoaded - { - add - { - GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.GameLoaded)}", "1.12", DeprecationLevel.PendingRemoval); - GameEvents._GameLoaded += value; - } - remove => GameEvents._GameLoaded -= value; - } - - /// <summary>Raised during the first game update tick.</summary> - [Obsolete("The " + nameof(Mod) + "." + nameof(Mod.Entry) + " method is now called after the game loads, so any contained logic can be done directly in " + nameof(Mod.Entry) + ".")] - public static event EventHandler FirstUpdateTick - { - add - { - GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(Game |
