TypeFieldToAnotherTypeMethodRewriter, a much more flexible choice to deal with fields changes

This commit is contained in:
yangzhi 2020-02-09 01:01:28 +08:00
parent fdf249c853
commit d0da995932
3 changed files with 14 additions and 1 deletions

View File

@ -43,7 +43,7 @@ namespace StardewModdingAPI.Framework.ModLoading
public static bool IsSameType(Type type, TypeReference reference) public static bool IsSameType(Type type, TypeReference reference)
{ {
// same namespace & name // same namespace & name
if (type.Namespace != reference.Namespace || type.Name != reference.Name) if ((type.Namespace != reference.Namespace || type.Name != reference.Name) && !(reference.Namespace == "" && reference.FullName.Replace("/", "+") == type.FullName))
return false; return false;
// same generic parameters // same generic parameters

View File

@ -53,6 +53,15 @@ namespace StardewModdingAPI.Metadata
yield return new PropertyToFieldRewriter(typeof(Game1), "toolSpriteSheet", "toolSpriteSheet"); yield return new PropertyToFieldRewriter(typeof(Game1), "toolSpriteSheet", "toolSpriteSheet");
// Accessibility fix
yield return new TypeFieldToAnotherTypeMethodRewriter(typeof(GameMenu), typeof(GameMenuMethods), "hoverText", "GetHoverText");
yield return new TypeFieldToAnotherTypeMethodRewriter(typeof(ShopMenu), typeof(ShopMenuMethods), "heldItem", "GetHeldItem");
yield return new TypeFieldToAnotherTypeMethodRewriter(typeof(ShopMenu), typeof(ShopMenuMethods), "hoveredItem", "GetHoveredItem");
yield return new TypeFieldToAnotherTypeMethodRewriter(typeof(ShopMenu), typeof(ShopMenuMethods), "hoverPrice", "GetHoverPrice");
yield return new TypeFieldToAnotherTypeMethodRewriter(typeof(ShopMenu), typeof(ShopMenuMethods), "hoverText", "GetHoverText");
yield return new TypeFieldToAnotherTypeMethodRewriter(typeof(ShopMenu), typeof(ShopMenuMethods), "categoriesToSellHere", "GetCategoriesToSellHere");
yield return new TypeFieldToAnotherTypeMethodRewriter(typeof(MenuWithInventory), typeof(MenuWithInventoryMethods), "trashCan", "GetTrashCan");
//Method Rewrites //Method Rewrites
yield return new MethodParentRewriter(typeof(Game1), typeof(Game1Methods)); yield return new MethodParentRewriter(typeof(Game1), typeof(Game1Methods));
yield return new MethodParentRewriter(typeof(Farmer), typeof(FarmerMethods)); yield return new MethodParentRewriter(typeof(Farmer), typeof(FarmerMethods));

View File

@ -235,6 +235,7 @@
<Compile Include="Framework\ModLoading\Rewriters\MethodParentRewriter.cs" /> <Compile Include="Framework\ModLoading\Rewriters\MethodParentRewriter.cs" />
<Compile Include="Framework\ModLoading\Rewriters\PropertyToFieldRewriter.cs" /> <Compile Include="Framework\ModLoading\Rewriters\PropertyToFieldRewriter.cs" />
<Compile Include="Framework\ModLoading\Rewriters\StaticFieldToConstantRewriter.cs" /> <Compile Include="Framework\ModLoading\Rewriters\StaticFieldToConstantRewriter.cs" />
<Compile Include="Framework\ModLoading\Rewriters\TypeFieldToAnotherTypeMethodRewriter.cs" />
<Compile Include="Framework\ModLoading\Rewriters\TypeFieldToAnotherTypeFieldRewriter.cs" /> <Compile Include="Framework\ModLoading\Rewriters\TypeFieldToAnotherTypeFieldRewriter.cs" />
<Compile Include="Framework\ModLoading\Rewriters\TypeReferenceRewriter.cs" /> <Compile Include="Framework\ModLoading\Rewriters\TypeReferenceRewriter.cs" />
<Compile Include="Framework\ModLoading\TypeReferenceComparer.cs" /> <Compile Include="Framework\ModLoading\TypeReferenceComparer.cs" />
@ -264,12 +265,15 @@
<Compile Include="Framework\Reflection\Reflector.cs" /> <Compile Include="Framework\Reflection\Reflector.cs" />
<Compile Include="Framework\RequestExitDelegate.cs" /> <Compile Include="Framework\RequestExitDelegate.cs" />
<Compile Include="Framework\RewriteFacades\DebrisMethods.cs" /> <Compile Include="Framework\RewriteFacades\DebrisMethods.cs" />
<Compile Include="Framework\RewriteFacades\GameMenuMethods.cs" />
<Compile Include="Framework\RewriteFacades\ShopMenuMethods.cs" />
<Compile Include="Framework\RewriteFacades\FarmerMethods.cs" /> <Compile Include="Framework\RewriteFacades\FarmerMethods.cs" />
<Compile Include="Framework\RewriteFacades\FarmerRenderMethods.cs" /> <Compile Include="Framework\RewriteFacades\FarmerRenderMethods.cs" />
<Compile Include="Framework\RewriteFacades\Game1Methods.cs" /> <Compile Include="Framework\RewriteFacades\Game1Methods.cs" />
<Compile Include="Framework\RewriteFacades\GameLocationMethods.cs" /> <Compile Include="Framework\RewriteFacades\GameLocationMethods.cs" />
<Compile Include="Framework\RewriteFacades\HUDMessageMethods.cs" /> <Compile Include="Framework\RewriteFacades\HUDMessageMethods.cs" />
<Compile Include="Framework\RewriteFacades\IClickableMenuMethods.cs" /> <Compile Include="Framework\RewriteFacades\IClickableMenuMethods.cs" />
<Compile Include="Framework\RewriteFacades\MenuWithInventoryMethods.cs" />
<Compile Include="Framework\RewriteFacades\ItemGrabMenuMethods.cs" /> <Compile Include="Framework\RewriteFacades\ItemGrabMenuMethods.cs" />
<Compile Include="Framework\RewriteFacades\MapPageMethods.cs" /> <Compile Include="Framework\RewriteFacades\MapPageMethods.cs" />
<Compile Include="Framework\RewriteFacades\NPCMethods.cs" /> <Compile Include="Framework\RewriteFacades\NPCMethods.cs" />