Skip to content

Commit

Permalink
prefer base in rewriters for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Feb 22, 2024
1 parent 720ebf2 commit 21abd0f
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 69 deletions.
3 changes: 3 additions & 0 deletions src/SMAPI/Framework/ModLoading/Framework/SuppressReasons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ internal static class SuppressReasons

/// <summary>A message indicating the code is used via assembly rewriting.</summary>
public const string UsedViaRewriting = "This code is used via assembly rewriting.";

/// <summary>A message indicating the code is used via assembly rewriting.</summary>
public const string BaseForClarity = "This code deliberately uses 'base' to ensure we're calling the real method instead of a rewritten one.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public static BedFurniture Constructor(int which, Vector2 tile)

public bool CanModifyBed(GameLocation location, Farmer who)
{
return this.CanModifyBed(who);
return base.CanModifyBed(who);
}

public bool IsBeingSleptIn(GameLocation location)
{
return this.IsBeingSleptIn();
return base.IsBeingSleptIn();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BreakableContainerFacade : BreakableContainer, IRewriteFacade
*********/
public void releaseContents(GameLocation location, Farmer who)
{
this.releaseContents(who);
base.releaseContents(who);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "ParameterHidesMember", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
[SuppressMessage("ReSharper", "UnusedParameter.Local", Justification = SuppressReasons.MatchesOriginal)]
public class BuffFacade : Buff, IRewriteFacade
Expand Down Expand Up @@ -46,7 +47,7 @@ public void addBuff()

public void removeBuff()
{
Game1.player.buffs.Remove(this.id);
Game1.player.buffs.Remove(base.id);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "ParameterHidesMember", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BuildableGameLocationFacade : GameLocation, IRewriteFacade
{
Expand Down Expand Up @@ -45,7 +46,7 @@ public class BuildableGameLocationFacade : GameLocation, IRewriteFacade

public Building? getBuildingUnderConstruction()
{
foreach (Building b in this.buildings)
foreach (Building b in base.buildings)
{
if (b.daysOfConstructionLeft > 0 || b.daysUntilUpgrade > 0)
return b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Building"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BuildingFacade : Building, IRewriteFacade
{
/*********
** Accessors
*********/
public NetRef<Chest> input => NetRefWrapperCache<Chest>.GetCachedWrapperFor(this.GetBuildingChest("Input")); // Mill
public NetRef<Chest> output => NetRefWrapperCache<Chest>.GetCachedWrapperFor(this.GetBuildingChest("Output")); // Mill
public NetRef<Chest> input => NetRefWrapperCache<Chest>.GetCachedWrapperFor(base.GetBuildingChest("Input")); // Mill
public NetRef<Chest> output => NetRefWrapperCache<Chest>.GetCachedWrapperFor(base.GetBuildingChest("Output")); // Mill


/*********
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Bush"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BushFacade : Bush, IRewriteFacade
{
Expand All @@ -21,15 +22,15 @@ public bool inBloom(string season, int dayOfMonth)
{
// call new method if possible
if (season == Game1.currentSeason && dayOfMonth == Game1.dayOfMonth)
return this.inBloom();
return base.inBloom();

// else mimic old behavior with 1.6 features
if (this.size == Bush.greenTeaBush)
if (base.size == Bush.greenTeaBush)
{
return
this.getAge() >= Bush.daysToMatureGreenTeaBush
base.getAge() >= Bush.daysToMatureGreenTeaBush
&& dayOfMonth >= 22
&& (season != "winter" || this.IsSheltered());
&& (season != "winter" || base.IsSheltered());
}

switch (season)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CaskFacade : Cask, IRewriteFacade
*********/
public bool IsValidCaskLocation(GameLocation location)
{
return this.IsValidCaskLocation();
return base.IsValidCaskLocation();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Character"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class CharacterFacade : Character, IRewriteFacade
{
Expand All @@ -18,37 +19,37 @@ public class CharacterFacade : Character, IRewriteFacade
*********/
public int getStandingX()
{
return this.StandingPixel.X;
return base.StandingPixel.X;
}

public int getStandingY()
{
return this.StandingPixel.Y;
return base.StandingPixel.Y;
}

public Point getStandingXY()
{
return this.StandingPixel;
return base.StandingPixel;
}

public Vector2 getTileLocation()
{
return this.Tile;
return base.Tile;
}

public Point getTileLocationPoint()
{
return this.TilePoint;
return base.TilePoint;
}

public int getTileX()
{
return this.TilePoint.X;
return base.TilePoint.X;
}

public int getTileY()
{
return this.TilePoint.Y;
return base.TilePoint.Y;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public ChestFacade(int coins, List<Item> items, Vector2 location, bool giftbox =

public void destroyAndDropContents(Vector2 pointToDropAt, GameLocation location)
{
this.destroyAndDropContents(pointToDropAt);
base.destroyAndDropContents(pointToDropAt);
}

public void dumpContents(GameLocation location)
{
this.dumpContents();
base.dumpContents();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
/// <summary>Maps Stardew Valley 1.5.6's <see cref="FarmAnimal"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class FarmAnimalFacade : FarmAnimal, IRewriteFacade
{
Expand All @@ -18,7 +19,7 @@ public class FarmAnimalFacade : FarmAnimal, IRewriteFacade
*********/
public bool isCoopDweller()
{
FarmAnimalData? data = this.GetAnimalData();
FarmAnimalData? data = base.GetAnimalData();
return data?.House == "Coop";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
[SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)]
public class FarmerFacade : Farmer, IRewriteFacade
{
/*********
Expand All @@ -34,12 +35,12 @@ public class FarmerFacade : Farmer, IRewriteFacade
*********/
public void addQuest(int questID)
{
this.addQuest(questID.ToString());
base.addQuest(questID.ToString());
}

public void changePants(Color color)
{
this.changePantsColor(color);
base.changePantsColor(color);
}

public void changePantStyle(int whichPants, bool is_customization_screen = false)
Expand All @@ -49,27 +50,27 @@ public void changePantStyle(int whichPants, bool is_customization_screen = false

public void changeShirt(int whichShirt, bool is_customization_screen = false)
{
this.changeShirt(whichShirt.ToString());
base.changeShirt(whichShirt.ToString());
}

public void changeShoeColor(int which)
{
this.changeShoeColor(which.ToString());
base.changeShoeColor(which.ToString());
}

public void completeQuest(int questID)
{
this.completeQuest(questID.ToString());
base.completeQuest(questID.ToString());
}

public bool couldInventoryAcceptThisObject(int index, int stack, int quality = 0)
{
return this.couldInventoryAcceptThisItem(index.ToString(), stack, quality);
return base.couldInventoryAcceptThisItem(index.ToString(), stack, quality);
}

public int GetEffectsOfRingMultiplier(int ring_index)
{
return this.GetEffectsOfRingMultiplier(ring_index.ToString());
return base.GetEffectsOfRingMultiplier(ring_index.ToString());
}

public int getItemCount(int item_index, int min_price = 0)
Expand All @@ -81,7 +82,7 @@ public int getItemCount(int item_index, int min_price = 0)

public bool hasBuff(int whichBuff)
{
return this.hasBuff(whichBuff.ToString());
return base.hasBuff(whichBuff.ToString());
}

public bool hasItemInInventory(int itemIndex, int quantity, int minPrice = 0)
Expand All @@ -91,24 +92,24 @@ public bool hasItemInInventory(int itemIndex, int quantity, int minPrice = 0)
switch (itemIndex)
{
case 858:
return this.QiGems >= quantity;
return base.QiGems >= quantity;

case 73:
return Game1.netWorldState.Value.GoldenWalnuts >= quantity;

default:
return this.getItemCount(ItemRegistry.type_object + itemIndex) >= quantity;
return base.getItemCount(ItemRegistry.type_object + itemIndex) >= quantity;
}
}

public bool hasQuest(int id)
{
return this.hasQuest(id.ToString());
return base.hasQuest(id.ToString());
}

public bool isWearingRing(int ringIndex)
{
return this.isWearingRing(ringIndex.ToString());
return base.isWearingRing(ringIndex.ToString());
}

public bool removeItemsFromInventory(int index, int stack)
Expand All @@ -118,7 +119,7 @@ public bool removeItemsFromInventory(int index, int stack)
switch (index)
{
case 858:
this.QiGems -= stack;
base.QiGems -= stack;
return true;

case 73:
Expand Down Expand Up @@ -152,7 +153,7 @@ public bool removeItemsFromInventory(int index, int stack)

public void removeQuest(int questID)
{
this.removeQuest(questID.ToString());
base.removeQuest(questID.ToString());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
/// <summary>Maps Stardew Valley 1.5.6's <see cref="FarmerTeam"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class FarmerTeamFacade : FarmerTeam, IRewriteFacade
{
/*********
** Accessors
*********/
public NetObjectList<Item> junimoChest => InventoryToNetObjectList.GetCachedWrapperFor(this.GetOrCreateGlobalInventory(FarmerTeam.GlobalInventoryId_JunimoChest));
public NetObjectList<Item> junimoChest => InventoryToNetObjectList.GetCachedWrapperFor(base.GetOrCreateGlobalInventory(FarmerTeam.GlobalInventoryId_JunimoChest));


/*********
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FenceFacade : Fence, IRewriteFacade
*********/
public void toggleGate(GameLocation location, bool open, bool is_toggling_counterpart = false, Farmer? who = null)
{
this.toggleGate(open, is_toggling_counterpart, who);
base.toggleGate(open, is_toggling_counterpart, who);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
/// <summary>Maps Stardew Valley 1.5.6's <see cref="FruitTree"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class FruitTreeFacade : FruitTree, IRewriteFacade
{
Expand All @@ -23,7 +24,7 @@ public NetString fruitSeason
{
get
{
List<Season>? seasons = this.GetData()?.Seasons;
List<Season>? seasons = base.GetData()?.Seasons;
string value = seasons?.Count > 0
? string.Join(",", seasons)
: string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public static Furniture Constructor(int which, Vector2 tile)

public void AddLightGlow(GameLocation location)
{
this.AddLightGlow();
base.AddLightGlow();
}

public void addLights(GameLocation environment)
{
this.addLights();
base.addLights();
}

public static Furniture GetFurnitureInstance(int index, Vector2? position = null)
Expand All @@ -44,17 +44,17 @@ public static Furniture GetFurnitureInstance(int index, Vector2? position = null

public void removeLights(GameLocation environment)
{
this.removeLights();
base.removeLights();
}

public void RemoveLightGlow(GameLocation location)
{
this.RemoveLightGlow();
base.RemoveLightGlow();
}

public void setFireplace(GameLocation location, bool playSound = true, bool broadcast = false)
{
this.setFireplace(playSound, broadcast);
base.setFireplace(playSound, broadcast);
}


Expand Down
Loading

0 comments on commit 21abd0f

Please sign in to comment.