diff options
Diffstat (limited to 'src/StardewModdingAPI/Framework')
75 files changed, 0 insertions, 7900 deletions
diff --git a/src/StardewModdingAPI/Framework/Command.cs b/src/StardewModdingAPI/Framework/Command.cs deleted file mode 100644 index 943e018d..00000000 --- a/src/StardewModdingAPI/Framework/Command.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; - -namespace StardewModdingAPI.Framework -{ - /// <summary>A command that can be submitted through the SMAPI console to interact with SMAPI.</summary> - internal class Command - { - /********* - ** Accessor - *********/ - /// <summary>The friendly name for the mod that registered the command.</summary> - public string ModName { get; } - - /// <summary>The command name, which the user must type to trigger it.</summary> - public string Name { get; } - - /// <summary>The human-readable documentation shown when the player runs the built-in 'help' command.</summary> - public string Documentation { get; } - - /// <summary>The method to invoke when the command is triggered. This method is passed the command name and arguments submitted by the user.</summary> - public Action<string, string[]> Callback { get; } - - - /********* - ** Public methods - *********/ - /// <summary>Construct an instance.</summary> - /// <param name="modName">The friendly name for the mod that registered the command.</param> - /// <param name="name">The command name, which the user must type to trigger it.</param> - /// <param name="documentation">The human-readable documentation shown when the player runs the built-in 'help' command.</param> - /// <param name="callback">The method to invoke when the command is triggered. This method is passed the command name and arguments submitted by the user.</param> - public Command(string modName, string name, string documentation, Action<string, string[]> callback) - { - this.ModName = modName; - this.Name = name; - this.Documentation = documentation; - this.Callback = callback; - } - } -} diff --git a/src/StardewModdingAPI/Framework/CommandManager.cs b/src/StardewModdingAPI/Framework/CommandManager.cs deleted file mode 100644 index 79a23d03..00000000 --- a/src/StardewModdingAPI/Framework/CommandManager.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace StardewModdingAPI.Framework -{ - /// <summary>Manages console commands.</summary> - internal class CommandManager - { - /********* - ** Properties - *********/ - /// <summary>The commands registered with SMAPI.</summary> - private readonly IDictionary<string, Command> Commands = new Dictionary<string, Command>(StringComparer.InvariantCultureIgnoreCase); - - - /********* - ** Public methods - *********/ - /// <summary>Add a console command.</summary> - /// <param name="modName">The friendly mod name for this instance.</param> - /// <param name="name">The command name, which the user must type to trigger it.</param> - /// <param name="documentation">The human-readable documentation shown when the player runs the built-in 'help' command.</param> - /// <param name="callback">The method to invoke when the command is triggered. This method is passed the command name and arguments submitted by the user.</param> - /// <param name="allowNullCallback">Whether to allow a null <paramref name="callback"/> argument; this should only used for backwards compatibility.</param> - /// <exception cref="ArgumentNullException">The <paramref name="name"/> or <paramref name="callback"/> is null or empty.</exception> - /// <exception cref="FormatException">The <paramref name="name"/> is not a valid format.</exception> - /// <exception cref="ArgumentException">There's already a command with that name.</exception> - public void Add(string modName, string name, string documentation, Action<string, string[]> callback, bool allowNullCallback = false) - { - name = this.GetNormalisedName(name); - - // validate format - if (string.IsNullOrWhiteSpace(name)) - throw new ArgumentNullException(nameof(name), "Can't register a command with no name."); - if (name.Any(char.IsWhiteSpace)) - throw new FormatException($"Can't register the '{name}' command because the name can't contain whitespace."); - if (callback == null && !allowNullCallback) - throw new ArgumentNullException(nameof(callback), $"Can't register the '{name}' command because without a callback."); - - // ensure uniqueness - if (this.Commands.ContainsKey(name)) - throw new ArgumentException(nameof(callback), $"Can't register the '{name}' command because there's already a command with that name."); - - // add command - this.Commands.Add(name, new Command(modName, name, documentation, callback)); - } - - /// <summary>Get a command by its unique name.</summary> - /// <param name="name">The command name.</param> - /// <returns>Returns the matching command, or <c>null</c> if not found.</returns> - public Command Get(string name) - { - name = this.GetNormalisedName(name); - this.Commands.TryGetValue(name, out Command command); - return command; - } - - /// <summary>Get all registered commands.</summary> - public IEnumerable<Command> GetAll() - { - return this.Commands - .Values - .OrderBy(p => p.Name); - } - - /// <summary>Trigger a command.</summary> - /// <param name="input">The raw command input.</param> - /// <returns>Returns whether a matching command was triggered.</returns> - public bool Trigger(string input) - { - if (string.IsNullOrWhiteSpace(input)) - return false; - - string[] args = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - string name = args[0]; - args = args.Skip(1).ToArray(); - - return this.Trigger(name, args); - } - - /// <summary>Trigger a command.</summary> - /// <param name="name">The command name.</param> - /// <param name="arguments">The command arguments.</param> - /// <returns>Returns whether a matching command was triggered.</returns> - public bool Trigger(string name, string[] arguments) - { - // get normalised name - name = this.GetNormalisedName(name); - if (name == null) - return false; - - // get command - if (this.Commands.TryGetValue(name, out Command command)) - { - command.Callback.Invoke(name, arguments); - return true; - } - return false; - } - - - /********* - ** Private methods - *********/ - /// <summary>Get a normalised command name.</summary> - /// <param name="name">The command name.</param> - private string GetNormalisedName(string name) - { - name = name?.Trim().ToLower(); - return !string.IsNullOrWhiteSpace(name) - ? name - : null; - } - } -} diff --git a/src/StardewModdingAPI/Framework/Content/AssetData.cs b/src/StardewModdingAPI/Framework/Content/AssetData.cs deleted file mode 100644 index 1ab9eebd..00000000 --- a/src/StardewModdingAPI/Framework/Content/AssetData.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; - -namespace StardewModdingAPI.Framework.Content -{ - /// <summary>Base implementation for a content helper which encapsulates access and changes to content being read from a data file.</summary> - /// <typeparam name="TValue">The interface value type.</typeparam> - internal class AssetData<TValue> : AssetInfo, IAssetData<TValue> - { - /********* - ** Accessors - *********/ - /// <summary>The content data being read.</summary> - public TValue Data { get; protected set; } - - - /********* - ** Public methods - *********/ - /// <summary>Construct an instance.</summary> - /// <param name="locale">The content's locale code, if the content is localised.</param> - /// <param name="assetName">The normalised asset name being read.</param> - /// <param name="data">The content data being read.</param> - /// <param name="getNormalisedPath">Normalises an asset key to match the cache key.</param> - public AssetData(string locale, string assetName, TValue data, Func<string, string> getNormalisedPath) - : base(locale, assetName, data.GetType(), getNormalisedPath) - { - this.Data = data; - } - - /// <summary>Replace the entire content value with the given value. This is generally not recommended, since it may break compatibility with other mods or different versions of the game.</summary> - /// <param name="value">The new content value.</param> - /// <exception cref="ArgumentNullException">The <paramref name="value"/> is null.</exception> - /// <exception cref="InvalidCastException">The <paramref name="value"/>'s type is not compatible with the loaded asset's type.</exception> - public void ReplaceWith(TValue value) - { - if (value == null) - throw new ArgumentNullException(nameof(value), "Can't set a loaded asset to a null value."); - if (!this.DataType.IsInstanceOfType(value)) - throw new InvalidCastException($"Can't replace loaded asset of type {this.GetFriendlyTypeName(this.DataType)} with value of type {this.GetFriendlyTypeName(value.GetType())}. The new type must be compatible to prevent game errors."); - - this.Data = value; - } - } -} diff --git a/src/StardewModdingAPI/Framework/Content/AssetDataForDictionary.cs b/src/StardewModdingAPI/Framework/Content/AssetDataForDictionary.cs deleted file mode 100644 index e9b29b12..00000000 --- a/src/StardewModdingAPI/Framework/Content/AssetDataForDictionary.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace StardewModdingAPI.Framework.Content -{ - /// <summary>Encapsulates access and changes to dictionary content being read from a data file.</summary> - internal class AssetDataForDictionary<TKey, TValue> : AssetData<IDictionary<TKey, TValue>>, IAssetDataForDictionary<TKey, TValue> - { - /********* - ** Public methods - *********/ - /// <summary>Construct an instance.</summary> - /// <param name="locale">The content's locale code, if the content is localised.</param> - /// <param name="assetName">The normalised asset name being read.</param> - /// <param name="data">The content data being read.</param> - /// <param name="getNormalisedPath">Normalises an asset key to match the cache key.</param> - public AssetDataForDictionary(string locale, string assetName, IDictionary<TKey, TValue> data, Func<string, string> getNormalisedPath) - : base(locale, assetName, data, getNormalisedPath) { } - - /// <summary>Add or replace an entry in the dictionary.</summary> - /// <param name="key">The entry key.</param> - /// <param name="value">The entry value.</param> - public void Set(TKey key, TValue value) - { - this.Data[key] = value; - } - - /// <summary>Add or replace an entry in the dictionary.</summary> - /// <param name="key">The entry key.</param> - /// <param name="value">A callback which accepts the current value and returns the new value.</param> - public void Set(TKey key, Func<TValue, TValue> value) - { - this.Data[key] = value(this.Data[key]); - } - - /// <summary>Dynamically replace values in the dictionary.</summary> - /// <param name="replacer">A lambda which takes the current key and value for an entry, and returns the new value.</param> - public void Set(Func<TKey, TValue, TValue> replacer) - { - foreach (var pair in this.Data.ToArray()) - this.Data[pair.Key] = replacer(pair.Key, pair.Value); - } - } -} diff --git a/src/StardewModdingAPI/Framework/Content/AssetDataForImage.cs b/src/StardewModdingAPI/Framework/Content/AssetDataForImage.cs deleted file mode 100644 index 45c5588b..00000000 --- a/src/StardewModdingAPI/Framework/Content/AssetDataForImage.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace StardewModdingAPI.Framework.Content -{ - /// <summary>Encapsulates access and changes to dictionary content being read from a data file.</summary> - internal class AssetDataForImage : AssetData<Texture2D>, IAssetDataForImage - { - /********* - ** Public methods - *********/ - /// <summary>Construct an instance.</summary> - /// <param name="locale">The content's locale code, if the content is localised.</param> - /// <param name="assetName">The normalised asset name being read.</param> - /// <param name="data">The content data being read.</param> - /// <param name="getNormalisedPath">Normalises an asset key to match the cache key.</param> - public AssetDataForImage(string locale, string assetName, Texture2D data, Func<string, string> getNormalisedPath) - : base(locale, assetName, data, getNormalisedPath) { } - - /// <summary>Overwrite part of the image.</summary> - /// <param name="source">The image to patch into the content.</param> - /// <param name="sourceArea">The part of the <paramref name="source"/> to copy (or <c>null</c> to take the whole texture). This must be within the bounds of the <paramref name="source"/> texture.</param> - /// <param name="targetArea">The part of the content to patch (or <c>null</c> to patch the whole texture). The original content within this area will be erased. This must be within the bounds of the existing spritesheet.</param> - /// <param name="patchMode">Indicates how an image should be patched.</param> - /// <exception cref="ArgumentNullException">One of the arguments is null.</exception> - /// <exception cref="ArgumentOutOfRangeException">The <paramref name="targetArea"/> is outside the bounds of the spritesheet.</exception> - public void PatchImage(Texture2D source, Rectangle? sourceArea = null, Rectangle? targetArea = null, PatchMode patchMode = PatchMode.Replace) - { - // get texture - Texture2D target = this.Data; - - // get areas - sourceArea = sourceArea ?? new Rectangle(0, 0, source.Width, source.Height); - targetArea = targetArea ?? new Rectangle(0, 0, Math.Min(sourceArea.Value.Width, target.Width), Math.Min(sourceArea.Value.Height, target.Height)); - - // validate - if (source == null) - throw new ArgumentNullException(nameof(source), "Can't patch from a null source texture."); - if (sourceArea.Value.X < 0 || sourceArea.Value.Y < 0 || sourceArea.Value.Right > source.Width || sourceArea.Value.Bottom > source.Height) - throw new ArgumentOutOfRangeException(nameof(sourceArea), "The source area is outside the bounds of the s |
