remove unused code (#837)

This commit is contained in:
Jesse Plamondon-Willard 2022-04-13 20:41:34 -04:00
parent f39da383a1
commit 5b24fff477
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
6 changed files with 2 additions and 104 deletions

View File

@ -1,15 +0,0 @@
namespace StardewModdingAPI.Events
{
/// <summary>Indicates how an inventory item changed.</summary>
public enum ChangeType
{
/// <summary>The entire stack was removed.</summary>
Removed,
/// <summary>The entire stack was added.</summary>
Added,
/// <summary>The stack size changed.</summary>
StackChange
}
}

View File

@ -36,11 +36,10 @@ namespace StardewModdingAPI.Framework
/// <param name="name">The command name, which the user must type to trigger it.</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="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="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="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="FormatException">The <paramref name="name"/> is not a valid format.</exception>
/// <exception cref="ArgumentException">There's already a command with that name.</exception> /// <exception cref="ArgumentException">There's already a command with that name.</exception>
public CommandManager Add(IModMetadata mod, string name, string documentation, Action<string, string[]> callback, bool allowNullCallback = false) public CommandManager Add(IModMetadata mod, string name, string documentation, Action<string, string[]> callback)
{ {
name = this.GetNormalizedName(name); name = this.GetNormalizedName(name);
@ -49,7 +48,7 @@ namespace StardewModdingAPI.Framework
throw new ArgumentNullException(nameof(name), "Can't register a command with no name."); throw new ArgumentNullException(nameof(name), "Can't register a command with no name.");
if (name.Any(char.IsWhiteSpace)) if (name.Any(char.IsWhiteSpace))
throw new FormatException($"Can't register the '{name}' command because the name can't contain whitespace."); throw new FormatException($"Can't register the '{name}' command because the name can't contain whitespace.");
if (callback == null && !allowNullCallback) if (callback == null)
throw new ArgumentNullException(nameof(callback), $"Can't register the '{name}' command because without a callback."); throw new ArgumentNullException(nameof(callback), $"Can't register the '{name}' command because without a callback.");
// ensure uniqueness // ensure uniqueness

View File

@ -394,22 +394,6 @@ namespace StardewModdingAPI.Framework.ModLoading
} }
} }
/// <summary>Get all mod folders in a root folder, passing through empty folders as needed.</summary>
/// <param name="rootPath">The root folder path to search.</param>
private IEnumerable<DirectoryInfo> GetModFolders(string rootPath)
{
foreach (string modRootPath in Directory.GetDirectories(rootPath))
{
DirectoryInfo directory = new(modRootPath);
// if a folder only contains another folder, check the inner folder instead
while (!directory.GetFiles().Any() && directory.GetDirectories().Length == 1)
directory = directory.GetDirectories().First();
yield return directory;
}
}
/// <summary>Get the dependencies declared in a manifest.</summary> /// <summary>Get the dependencies declared in a manifest.</summary>
/// <param name="manifest">The mod manifest.</param> /// <param name="manifest">The mod manifest.</param>
/// <param name="loadedMods">The loaded mods.</param> /// <param name="loadedMods">The loaded mods.</param>

View File

@ -1,7 +1,6 @@
#nullable disable #nullable disable
using System; using System;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.Caching; using System.Runtime.Caching;
@ -128,41 +127,6 @@ namespace StardewModdingAPI.Framework.Reflection
return method; return method;
} }
/****
** Methods by signature
****/
/// <summary>Get a instance method.</summary>
/// <param name="obj">The object which has the method.</param>
/// <param name="name">The field name.</param>
/// <param name="argumentTypes">The argument types of the method signature to find.</param>
/// <param name="required">Whether to throw an exception if the field is not found.</param>
public IReflectedMethod GetMethod(object obj, string name, Type[] argumentTypes, bool required = true)
{
// validate parent
if (obj == null)
throw new ArgumentNullException(nameof(obj), "Can't get a instance method from a null object.");
// get method from hierarchy
ReflectedMethod method = this.GetMethodFromHierarchy(obj.GetType(), obj, name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, argumentTypes);
if (required && method == null)
throw new InvalidOperationException($"The {obj.GetType().FullName} object doesn't have a '{name}' instance method with that signature.");
return method;
}
/// <summary>Get a static method.</summary>
/// <param name="type">The type which has the method.</param>
/// <param name="name">The field name.</param>
/// <param name="argumentTypes">The argument types of the method signature to find.</param>
/// <param name="required">Whether to throw an exception if the field is not found.</param>
public IReflectedMethod GetMethod(Type type, string name, Type[] argumentTypes, bool required = true)
{
// get field from hierarchy
ReflectedMethod method = this.GetMethodFromHierarchy(type, null, name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, argumentTypes);
if (required && method == null)
throw new InvalidOperationException($"The {type.FullName} object doesn't have a '{name}' static method with that signature.");
return method;
}
/********* /*********
** Private methods ** Private methods
@ -232,27 +196,6 @@ namespace StardewModdingAPI.Framework.Reflection
: null; : null;
} }
/// <summary>Get a method from the type hierarchy.</summary>
/// <param name="type">The type which has the method.</param>
/// <param name="obj">The object which has the method.</param>
/// <param name="name">The method name.</param>
/// <param name="bindingFlags">The reflection binding which flags which indicates what type of method to find.</param>
/// <param name="argumentTypes">The argument types of the method signature to find.</param>
private ReflectedMethod GetMethodFromHierarchy(Type type, object obj, string name, BindingFlags bindingFlags, Type[] argumentTypes)
{
bool isStatic = bindingFlags.HasFlag(BindingFlags.Static);
MethodInfo method = this.GetCached($"method::{isStatic}::{type.FullName}::{name}({string.Join(",", argumentTypes.Select(p => p.FullName))})", () =>
{
MethodInfo methodInfo = null;
for (; type != null && methodInfo == null; type = type.BaseType)
methodInfo = type.GetMethod(name, bindingFlags, null, argumentTypes, null);
return methodInfo;
});
return method != null
? new ReflectedMethod(type, obj, method, isStatic)
: null;
}
/// <summary>Get a method or field through the cache.</summary> /// <summary>Get a method or field through the cache.</summary>
/// <typeparam name="TMemberInfo">The expected <see cref="MemberInfo"/> type.</typeparam> /// <typeparam name="TMemberInfo">The expected <see cref="MemberInfo"/> type.</typeparam>
/// <param name="key">The cache key.</param> /// <param name="key">The cache key.</param>

View File

@ -1,9 +0,0 @@
#nullable disable
namespace StardewModdingAPI.Framework
{
/// <summary>A delegate which requests that SMAPI immediately exit the game. This should only be invoked when an irrecoverable fatal error happens that risks save corruption or game-breaking bugs.</summary>
/// <param name="module">The module which requested an immediate exit.</param>
/// <param name="reason">The reason provided for the shutdown.</param>
internal delegate void RequestExitDelegate(string module, string reason);
}

View File

@ -2,7 +2,6 @@ using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Events; using StardewModdingAPI.Events;
@ -64,9 +63,6 @@ namespace StardewModdingAPI.Framework
/// <summary>Manages input visible to the game.</summary> /// <summary>Manages input visible to the game.</summary>
public SInputState Input => (SInputState)Game1.input; public SInputState Input => (SInputState)Game1.input;
/// <summary>The game background task which initializes a new day.</summary>
public Task NewDayTask => Game1._newDayTask;
/// <summary>Monitors the entire game state for changes.</summary> /// <summary>Monitors the entire game state for changes.</summary>
public WatcherCore Watchers { get; private set; } = null!; // initialized on first update tick public WatcherCore Watchers { get; private set; } = null!; // initialized on first update tick