From da7e7098c2bf0a30d3cf4c067f08708785043d98 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 22 Feb 2024 01:05:12 -0500 Subject: [PATCH] improve rewriters for Stardew Valley 1.6 --- .../BasicProjectileFacade.cs | 61 ++++ .../StardewValley_1_6/BoatTunnelFacade.cs | 31 ++ .../StardewValley_1_6/BootsFacade.cs | 13 + .../StardewValley_1_6/BreakableContainer.cs | 21 ++ .../StardewValley_1_6/BuffsDisplayFacade.cs | 33 ++ .../StardewValley_1_6/CharacterFacade.cs | 6 + .../StardewValley_1_6/ChestFacade.cs | 17 +- .../DebuffingProjectileFacade.cs | 46 +++ .../StardewValley_1_6/DelayedActionFacade.cs | 6 + .../StardewValley_1_6/FarmerFacade.cs | 21 ++ .../StardewValley_1_6/FenceFacade.cs | 6 + .../FishTankFurnitureFacade.cs | 38 ++ .../StardewValley_1_6/ForestFacade.cs | 7 +- .../StardewValley_1_6/FruitTreeFacade.cs | 11 + .../StardewValley_1_6/Game1Facade.cs | 51 ++- .../StardewValley_1_6/HoeDirtFacade.cs | 5 + .../StardewValley_1_6/MeleeWeaponFacade.cs | 6 + .../StardewValley_1_6/MineShaftFacade.cs | 37 ++ .../StardewValley_1_6/MultiplayerFacade.cs | 36 ++ .../StardewValley_1_6/NetWorldStateFacade.cs | 33 ++ .../Rewriters/StardewValley_1_6/NpcFacade.cs | 30 ++ .../StardewValley_1_6/ObjectFacade.cs | 5 + .../StardewValley_1_6/QuestFacade.cs | 32 ++ .../Rewriters/StardewValley_1_6/RingFacade.cs | 17 + .../Rewriters/StardewValley_1_6/SignFacade.cs | 32 ++ .../StardewValley_1_6/SpriteTextFacade.cs | 32 ++ .../StardewValley_1_6/StatsFacade.cs | 343 ++++++++++++++++++ .../TemporaryAnimatedSpriteFacade.cs | 34 ++ .../StardewValley_1_6/TerrainFeatureFacade.cs | 16 + .../Rewriters/StardewValley_1_6/TvFacade.cs | 33 ++ .../StardewValley_1_6/UtilityFacade.cs | 8 + src/SMAPI/Metadata/InstructionMetadata.cs | 47 ++- 32 files changed, 1091 insertions(+), 23 deletions(-) create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BasicProjectileFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BoatTunnelFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BuffsDisplayFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/DebuffingProjectileFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FishTankFurnitureFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MineShaftFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MultiplayerFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/NetWorldStateFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/QuestFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/SignFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/StatsFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TemporaryAnimatedSpriteFacade.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TvFacade.cs diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BasicProjectileFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BasicProjectileFacade.cs new file mode 100644 index 000000000..cefb0be29 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BasicProjectileFacade.cs @@ -0,0 +1,61 @@ +using System.Diagnostics.CodeAnalysis; +using Microsoft.Xna.Framework; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley; +using StardewValley.Projectiles; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "IdentifierTypo", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class BasicProjectileFacade : BasicProjectile, IRewriteFacade + { + /********* + ** Public methods + *********/ + public static BasicProjectile Constructor(int damageToFarmer, int parentSheetIndex, int bouncesTillDestruct, int tailLength, float rotationVelocity, float xVelocity, float yVelocity, Vector2 startingPosition, string collisionSound, string firingSound, bool explode, bool damagesMonsters = false, GameLocation? location = null, Character? firer = null, bool spriteFromObjectSheet = false, onCollisionBehavior? collisionBehavior = null) + { + var projectile = new BasicProjectile( + damageToFarmer: damageToFarmer, + spriteIndex: parentSheetIndex, + bouncesTillDestruct: bouncesTillDestruct, + tailLength: tailLength, + rotationVelocity: rotationVelocity, + xVelocity: xVelocity, + yVelocity: yVelocity, + startingPosition: startingPosition + ); + + projectile.explode.Value = explode; + projectile.collisionSound.Value = collisionSound; + projectile.damagesMonsters.Value = damagesMonsters; + projectile.theOneWhoFiredMe.Set(location, firer); + projectile.itemId.Value = spriteFromObjectSheet ? parentSheetIndex.ToString() : null; + projectile.collisionBehavior = collisionBehavior; + + if (!string.IsNullOrWhiteSpace(firingSound) && location != null) + location.playSound(firingSound); + + return projectile; + } + + public static BasicProjectile Constructor(int damageToFarmer, int parentSheetIndex, int bouncesTillDestruct, int tailLength, float rotationVelocity, float xVelocity, float yVelocity, Vector2 startingPosition) + { + return Constructor(damageToFarmer, parentSheetIndex, bouncesTillDestruct, tailLength, rotationVelocity, xVelocity, yVelocity, startingPosition, "flameSpellHit", "flameSpell", true); + } + + + /********* + ** Private methods + *********/ + private BasicProjectileFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BoatTunnelFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BoatTunnelFacade.cs new file mode 100644 index 000000000..f76f8ca21 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BoatTunnelFacade.cs @@ -0,0 +1,31 @@ +using System.Diagnostics.CodeAnalysis; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley.Locations; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class BoatTunnelFacade : BoatTunnel, IRewriteFacade + { + /********* + ** Public methods + *********/ + public int GetTicketPrice() + { + return base.TicketPrice; + } + + + /********* + ** Private methods + *********/ + private BoatTunnelFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BootsFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BootsFacade.cs index 5c240ef18..a3e1a37f6 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BootsFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BootsFacade.cs @@ -1,5 +1,6 @@ using System.Diagnostics.CodeAnalysis; using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley; using StardewValley.Objects; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. @@ -8,6 +9,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 { /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "IdentifierTypo", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] public class BootsFacade : Boots, IRewriteFacade { @@ -19,6 +22,16 @@ public static Boots Constructor(int which) return new Boots(which.ToString()); } + public virtual void onEquip() + { + base.onEquip(Game1.player); + } + + public virtual void onUnequip() + { + base.onUnequip(Game1.player); + } + /********* ** Private methods diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BreakableContainer.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BreakableContainer.cs index e9eaea59b..244842e68 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BreakableContainer.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BreakableContainer.cs @@ -1,6 +1,8 @@ using System.Diagnostics.CodeAnalysis; +using Microsoft.Xna.Framework; using StardewModdingAPI.Framework.ModLoading.Framework; using StardewValley; +using StardewValley.Locations; using StardewValley.Objects; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. @@ -16,6 +18,25 @@ public class BreakableContainerFacade : BreakableContainer, IRewriteFacade /********* ** Public methods *********/ + public static BreakableContainer Constructor(Vector2 tile, int type, MineShaft mine) + { + var container = BreakableContainer.GetBarrelForMines(tile, mine); + + if (type.ToString() != BreakableContainer.barrelId) + { +#pragma warning disable CS0618 // obsolete code -- it's used for its intended purpose here + container.SetIdAndSprite(type); +#pragma warning restore CS0618 + } + + return container; + } + + public static BreakableContainer Constructor(Vector2 tile, bool isVolcano) + { + return BreakableContainer.GetBarrelForVolcanoDungeon(tile); + } + public void releaseContents(GameLocation location, Farmer who) { base.releaseContents(who); diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BuffsDisplayFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BuffsDisplayFacade.cs new file mode 100644 index 000000000..3d2cd528e --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BuffsDisplayFacade.cs @@ -0,0 +1,33 @@ +using System.Diagnostics.CodeAnalysis; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley; +using StardewValley.Menus; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class BuffsDisplayFacade : BuffsDisplay, IRewriteFacade + { + /********* + ** Public methods + *********/ + public bool hasBuff(int which) + { + return Game1.player.hasBuff(which.ToString()); + } + + + /********* + ** Private methods + *********/ + private BuffsDisplayFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/CharacterFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/CharacterFacade.cs index 8b11a9ad2..644385d27 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/CharacterFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/CharacterFacade.cs @@ -17,6 +17,12 @@ public class CharacterFacade : Character, IRewriteFacade /********* ** Public methods *********/ + public new int addedSpeed + { + get => (int)base.addedSpeed; + set => base.addedSpeed = value; + } + public int getStandingX() { return base.StandingPixel.X; diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ChestFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ChestFacade.cs index 7c18b047f..1604c33fa 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ChestFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ChestFacade.cs @@ -43,11 +43,15 @@ public static Chest Constructor(Vector2 location) return new Chest { TileLocation = location }; } - public ChestFacade(int parent_sheet_index, Vector2 tile_location, int starting_lid_frame, int lid_frame_count) - : base(parent_sheet_index.ToString(), tile_location, starting_lid_frame, lid_frame_count) { } + public static Chest Constructor(int parent_sheet_index, Vector2 tile_location, int starting_lid_frame, int lid_frame_count) + { + return new Chest(parent_sheet_index.ToString(), tile_location, starting_lid_frame, lid_frame_count); + } - public ChestFacade(int coins, List items, Vector2 location, bool giftbox = false, int giftboxIndex = 0) - : base(items, location, giftbox, giftboxIndex) { } + public static Chest Constructor(int coins, List items, Vector2 location, bool giftbox = false, int giftboxIndex = 0) + { + return new Chest(items, location, giftbox, giftboxIndex); + } public void destroyAndDropContents(Vector2 pointToDropAt, GameLocation location) { @@ -59,6 +63,11 @@ public void dumpContents(GameLocation location) base.dumpContents(); } + public void updateWhenCurrentLocation(GameTime time, GameLocation environment) + { + base.updateWhenCurrentLocation(time); + } + /********* ** Private methods diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/DebuffingProjectileFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/DebuffingProjectileFacade.cs new file mode 100644 index 000000000..38cf0a9ef --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/DebuffingProjectileFacade.cs @@ -0,0 +1,46 @@ +using System.Diagnostics.CodeAnalysis; +using Microsoft.Xna.Framework; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley; +using StardewValley.Projectiles; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "IdentifierTypo", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class DebuffingProjectileFacade : DebuffingProjectile, IRewriteFacade + { + /********* + ** Public methods + *********/ + public static DebuffingProjectile Constructor(int debuff, int parentSheetIndex, int bouncesTillDestruct, int tailLength, float rotationVelocity, float xVelocity, float yVelocity, Vector2 startingPosition, GameLocation? location = null, Character? owner = null) + { + return new DebuffingProjectile( + debuff: debuff.ToString(), + spriteIndex: parentSheetIndex, + bouncesTillDestruct: bouncesTillDestruct, + tailLength: tailLength, + rotationVelocity: rotationVelocity, + xVelocity: xVelocity, + yVelocity: yVelocity, + startingPosition: startingPosition, + location: location, + owner: owner + ); + } + + + /********* + ** Private methods + *********/ + private DebuffingProjectileFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/DelayedActionFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/DelayedActionFacade.cs index d6de9253f..6021efaaa 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/DelayedActionFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/DelayedActionFacade.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics.CodeAnalysis; using StardewModdingAPI.Framework.ModLoading.Framework; using StardewValley; @@ -15,6 +16,11 @@ public class DelayedActionFacade : DelayedAction, IRewriteFacade /********* ** Public methods *********/ + public new static void functionAfterDelay(Action func, int timer) + { + DelayedAction.functionAfterDelay(func, timer); + } + public static void playSoundAfterDelay(string soundName, int timer, GameLocation? location = null, int pitch = -1) { DelayedAction.playSoundAfterDelay(soundName, timer, location, pitch: pitch); diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FarmerFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FarmerFacade.cs index 6452db005..fbad5b177 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FarmerFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FarmerFacade.cs @@ -23,6 +23,17 @@ public class FarmerFacade : Farmer, IRewriteFacade *********/ public NetObjectList items => InventoryToNetObjectList.GetCachedWrapperFor(base.Items); + public int attack => base.buffs.Attack; + public int immunity => base.buffs.Immunity; + public int resilience => base.buffs.Defense; + + public float attackIncreaseModifier => base.buffs.AttackMultiplier; + public float critChanceModifier => base.buffs.CriticalChanceMultiplier; + public float critPowerModifier => base.buffs.CriticalPowerMultiplier; + public float knockbackModifier => base.buffs.KnockbackMultiplier; + public float weaponPrecisionModifier => base.buffs.WeaponPrecisionMultiplier; + public float weaponSpeedModifier => base.buffs.WeaponSpeedMultiplier; + public new IList Items { get => base.Items; @@ -107,11 +118,21 @@ public bool hasQuest(int id) return base.hasQuest(id.ToString()); } + public bool isMarried() + { + return base.isMarriedOrRoommates(); + } + public bool isWearingRing(int ringIndex) { return base.isWearingRing(ringIndex.ToString()); } + public void removeFirstOfThisItemFromInventory(int parentSheetIndexOfItem) + { + base.removeFirstOfThisItemFromInventory(parentSheetIndexOfItem.ToString()); + } + public bool removeItemsFromInventory(int index, int stack) { if (this.hasItemInInventory(index, stack)) diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FenceFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FenceFacade.cs index 802280120..788f4d8ef 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FenceFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FenceFacade.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using Microsoft.Xna.Framework; using StardewModdingAPI.Framework.ModLoading.Framework; using StardewValley; @@ -15,6 +16,11 @@ public class FenceFacade : Fence, IRewriteFacade /********* ** Public methods *********/ + public static Fence Constructor(Vector2 tileLocation, int whichType, bool isGate) + { + return new Fence(tileLocation, whichType.ToString(), isGate); + } + public void toggleGate(GameLocation location, bool open, bool is_toggling_counterpart = false, Farmer? who = null) { base.toggleGate(open, is_toggling_counterpart, who); diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FishTankFurnitureFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FishTankFurnitureFacade.cs new file mode 100644 index 000000000..5db1b8e26 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FishTankFurnitureFacade.cs @@ -0,0 +1,38 @@ +using System.Diagnostics.CodeAnalysis; +using Microsoft.Xna.Framework; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley.Objects; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class FishTankFurnitureFacade : FishTankFurniture, IRewriteFacade + { + /********* + ** Public methods + *********/ + public static FishTankFurniture Constructor(int which, Vector2 tile, int initialRotations) + { + return new FishTankFurniture(which.ToString(), tile, initialRotations); + } + + public static FishTankFurniture Constructor(int which, Vector2 tile) + { + return new FishTankFurniture(which.ToString(), tile); + } + + + /********* + ** Private methods + *********/ + private FishTankFurnitureFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ForestFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ForestFacade.cs index e702fe1c9..16f8eace8 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ForestFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ForestFacade.cs @@ -10,6 +10,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)] [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] public class ForestFacade : Forest, IRewriteFacade { @@ -20,7 +21,7 @@ public ResourceClump? log { get { - foreach (ResourceClump clump in this.resourceClumps) + foreach (ResourceClump clump in base.resourceClumps) { if (clump.parentSheetIndex.Value == ResourceClump.hollowLogIndex && (int)clump.Tile.X == 2 && (int)clump.Tile.Y == 6) return clump; @@ -33,11 +34,11 @@ public ResourceClump? log // remove previous value ResourceClump? clump = this.log; if (clump != null) - this.resourceClumps.Remove(clump); + base.resourceClumps.Remove(clump); // add new value if (value != null) - this.resourceClumps.Add(value); + base.resourceClumps.Add(value); } } diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FruitTreeFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FruitTreeFacade.cs index 0aebc33cd..141967df1 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FruitTreeFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FruitTreeFacade.cs @@ -4,6 +4,7 @@ using StardewModdingAPI.Framework.ModLoading.Framework; using StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6.Internal; using StardewValley; +using StardewValley.Objects; using StardewValley.TerrainFeatures; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. @@ -20,6 +21,16 @@ public class FruitTreeFacade : FruitTree, IRewriteFacade /********* ** Accessors *********/ + public static FruitTree Constructor(int saplingIndex) + { + return new FruitTree(saplingIndex.ToString()); + } + + public static FruitTree Constructor(int saplingIndex, int growthStage) + { + return new FruitTree(saplingIndex.ToString(), growthStage); + } + public NetString fruitSeason { get diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/Game1Facade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/Game1Facade.cs index be532edb0..d1d0da1b8 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/Game1Facade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/Game1Facade.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.ModLoading.Framework; @@ -17,7 +18,6 @@ public class Game1Facade : IRewriteFacade /********* ** Accessors *********/ - [SuppressMessage("ReSharper", "ValueParameterNotUsed")] public static bool menuUp { get; set; } // field was mostly unused and always false @@ -31,17 +31,6 @@ public static bool canHaveWeddingOnDay(int day, string season) && Game1.canHaveWeddingOnDay(day, parsedSeason); } - public static NPC getCharacterFromName(string name, bool mustBeVillager = true, bool useLocationsListOnly = false) - { - return Game1.getCharacterFromName(name, mustBeVillager); - } - - public static string GetSeasonForLocation(GameLocation location) - { - Season season = Game1.GetSeasonForLocation(location); - return season.ToString(); - } - public static void createMultipleObjectDebris(int index, int xTile, int yTile, int number) { Game1.createMultipleObjectDebris(index.ToString(), xTile, yTile, number); @@ -87,6 +76,21 @@ public static void createObjectDebris(int objectIndex, int xTile, int yTile, int Game1.createObjectDebris(objectIndex.ToString(), xTile, yTile, groundLevel, itemQuality, velocityMultiplyer, location); } + public static void createRadialDebris(GameLocation location, int debrisType, int xTile, int yTile, int numberOfChunks, bool resource, int groundLevel = -1, bool item = false, int color = -1) + { + Game1.createRadialDebris( + location: location, + debrisType: debrisType, + xTile: xTile, + yTile: yTile, + numberOfChunks: numberOfChunks, + resource: resource, + groundLevel: groundLevel, + item: item, + color: Debris.getColorForDebris(color) + ); + } + public static void drawDialogue(NPC speaker, string dialogue) { Game1.DrawDialogue(new Dialogue(speaker, null, dialogue)); @@ -97,6 +101,29 @@ public static void drawDialogue(NPC speaker, string dialogue, Texture2D override Game1.DrawDialogue(new Dialogue(speaker, null, dialogue) { overridePortrait = overridePortrait }); } + public static void drawObjectQuestionDialogue(string dialogue, List choices, int width) + { + Game1.drawObjectQuestionDialogue(dialogue, choices?.ToArray(), width); + + } + + public static void drawObjectQuestionDialogue(string dialogue, List choices) + { + Game1.drawObjectQuestionDialogue(dialogue, choices?.ToArray()); + } + + public static NPC getCharacterFromName(string name, bool mustBeVillager = true, bool useLocationsListOnly = false) + { + return Game1.getCharacterFromName(name, mustBeVillager); + } + + public static string GetSeasonForLocation(GameLocation location) + { + Season season = Game1.GetSeasonForLocation(location); + return season.ToString(); + } + + /********* ** Private methods diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/HoeDirtFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/HoeDirtFacade.cs index 96deb8fe3..472d4ab28 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/HoeDirtFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/HoeDirtFacade.cs @@ -32,6 +32,11 @@ public bool plant(int index, int tileX, int tileY, Farmer who, bool isFertilizer return base.plant(index.ToString(), who, isFertilizer); } + public void updateNeighbors(GameLocation loc, Vector2 tilePos) + { + base.updateNeighbors(); + } + /********* ** Private methods diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MeleeWeaponFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MeleeWeaponFacade.cs index 9c6279c9c..0483d6503 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MeleeWeaponFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MeleeWeaponFacade.cs @@ -8,6 +8,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 { /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] public class MeleeWeaponFacade : MeleeWeapon, IRewriteFacade { @@ -19,6 +20,11 @@ public static MeleeWeapon Constructor(int spriteIndex) return new MeleeWeapon(spriteIndex.ToString()); } + public bool isScythe(int index = -1) + { + return base.isScythe(); // index argument was already ignored + } + /********* ** Private methods diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MineShaftFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MineShaftFacade.cs new file mode 100644 index 000000000..50b71a197 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MineShaftFacade.cs @@ -0,0 +1,37 @@ +using System.Diagnostics.CodeAnalysis; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley; +using StardewValley.Locations; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class MineShaftFacade : MineShaft, IRewriteFacade + { + /********* + ** Public methods + *********/ + public new int getRandomGemRichStoneForThisLevel(int level) + { + string itemId = base.getRandomGemRichStoneForThisLevel(level); + + return int.TryParse(itemId, out int index) + ? index + : Object.mineStoneBrown1Index; // old default value + } + + + /********* + ** Private methods + *********/ + private MineShaftFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MultiplayerFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MultiplayerFacade.cs new file mode 100644 index 000000000..f5d32b20d --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/MultiplayerFacade.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class MultiplayerFacade : Multiplayer, IRewriteFacade + { + /********* + ** Public methods + *********/ + public void broadcastSprites(GameLocation location, List sprites) + { + var list = new TemporaryAnimatedSpriteList(); + list.AddRange(sprites); + + base.broadcastSprites(location, list); + } + + + /********* + ** Private methods + *********/ + private MultiplayerFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/NetWorldStateFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/NetWorldStateFacade.cs new file mode 100644 index 000000000..ad88325cf --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/NetWorldStateFacade.cs @@ -0,0 +1,33 @@ +using System.Diagnostics.CodeAnalysis; +using Netcode; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley.Network; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class NetWorldStateFacade : NetWorldState, IRewriteFacade + { + /********* + ** Public methods + *********/ + public new NetIntDelta MiniShippingBinsObtained => base.miniShippingBinsObtained; + public new NetIntDelta GoldenWalnutsFound => base.goldenWalnutsFound; + public new NetIntDelta GoldenWalnuts => base.goldenWalnuts; + public new NetBool GoldenCoconutCracked => base.goldenCoconutCracked; + public new NetBool ParrotPlatformsUnlocked => base.parrotPlatformsUnlocked; + + /********* + ** Private methods + *********/ + private NetWorldStateFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/NpcFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/NpcFacade.cs index 28e901025..d57e88e52 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/NpcFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/NpcFacade.cs @@ -1,5 +1,7 @@ +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.ModLoading.Framework; using StardewValley; using StardewValley.BellsAndWhistles; @@ -15,9 +17,37 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] public abstract class NpcFacade : NPC, IRewriteFacade { + /********* + ** Accessors + *********/ + public new int Gender + { + get => (int)base.Gender; + set => base.Gender = (Gender)value; + } + + /********* ** Public methods *********/ + public static NPC Constructor(AnimatedSprite sprite, Vector2 position, string defaultMap, int facingDirection, string name, bool datable, Dictionary schedule, Texture2D portrait) + { + return new NPC(sprite, position, defaultMap, facingDirection, name, datable, portrait); + } + + public static NPC Constructor(AnimatedSprite sprite, Vector2 position, string defaultMap, int facingDir, string name, Dictionary schedule, Texture2D portrait, bool eventActor, string? syncedPortraitPath = null) + { + NPC npc = new NPC(sprite, position, defaultMap, facingDir, name, portrait, eventActor); + + if (!string.IsNullOrWhiteSpace(syncedPortraitPath)) + { + npc.Portrait = Game1.content.Load(syncedPortraitPath); + npc.portraitOverridden = true; + } + + return npc; + } + public bool isBirthday(string season, int day) { // call new method if possible diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ObjectFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ObjectFacade.cs index 4b6fa2254..fc6b6c178 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ObjectFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ObjectFacade.cs @@ -57,6 +57,11 @@ public void ApplySprinkler(GameLocation location, Vector2 tile) base.ApplySprinkler(tile); } + public void ApplySprinklerAnimation(GameLocation location) + { + base.ApplySprinklerAnimation(); + } + public void DayUpdate(GameLocation location) { base.DayUpdate(); diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/QuestFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/QuestFacade.cs new file mode 100644 index 000000000..5f4fed0a9 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/QuestFacade.cs @@ -0,0 +1,32 @@ +using System.Diagnostics.CodeAnalysis; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley.Quests; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class QuestFacade : Quest, IRewriteFacade + { + /********* + ** Public methods + *********/ + public static Quest getQuestFromId(int id) + { + return Quest.getQuestFromId(id.ToString()); + } + + + /********* + ** Private methods + *********/ + private QuestFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/RingFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/RingFacade.cs index 2f891f229..84b6e5f8d 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/RingFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/RingFacade.cs @@ -1,5 +1,6 @@ using System.Diagnostics.CodeAnalysis; using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley; using StardewValley.Objects; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. @@ -8,6 +9,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 { /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] public class RingFacade : Ring, IRewriteFacade { @@ -19,6 +21,21 @@ public static Ring Constructor(int which) return new Ring(which.ToString()); } + public virtual bool GetsEffectOfRing(int ring_index) + { + return base.GetsEffectOfRing(ring_index.ToString()); + } + + public virtual void onEquip(Farmer who, GameLocation location) + { + base.onEquip(who); + } + + public virtual void onUnequip(Farmer who, GameLocation location) + { + base.onUnequip(who); + } + /********* ** Private methods diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/SignFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/SignFacade.cs new file mode 100644 index 000000000..c25187e23 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/SignFacade.cs @@ -0,0 +1,32 @@ +using System.Diagnostics.CodeAnalysis; +using Microsoft.Xna.Framework; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley.Objects; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class SignFacade : Sign, IRewriteFacade + { + /********* + ** Public methods + *********/ + public static Sign Constructor(Vector2 tile, int which) + { + return new Sign(tile, which.ToString()); + } + + + /********* + ** Private methods + *********/ + private SignFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/SpriteTextFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/SpriteTextFacade.cs index a189f6b06..7c0b4024c 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/SpriteTextFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/SpriteTextFacade.cs @@ -38,6 +38,20 @@ public static void drawString(SpriteBatch b, string s, int x, int y, int charact ); } + public static void drawStringWithScrollBackground(SpriteBatch b, string s, int x, int y, string placeHolderWidthText = "", float alpha = 1f, int color = -1, ScrollTextAlignment scroll_text_alignment = ScrollTextAlignment.Left) + { + SpriteText.drawStringWithScrollBackground( + b: b, + s: s, + x: x, + y: y, + placeHolderWidthText: placeHolderWidthText, + alpha: alpha, + color: color != -1 ? SpriteText.getColorFromIndex(color) : null, + scroll_text_alignment: scroll_text_alignment + ); + } + public static void drawStringWithScrollCenteredAt(SpriteBatch b, string s, int x, int y, int width, float alpha = 1f, int color = -1, int scrollType = SpriteText.scrollStyle_scroll, float layerDepth = .88f, bool junimoText = false) { SpriteText.drawStringWithScrollCenteredAt( @@ -70,6 +84,24 @@ public static void drawStringWithScrollCenteredAt(SpriteBatch b, string s, int x ); } + public static void drawStringHorizontallyCenteredAt(SpriteBatch b, string s, int x, int y, int characterPosition = maxCharacter, int width = -1, int height = maxHeight, float alpha = 1f, float layerDepth = .88f, bool junimoText = false, int color = -1, int maxWidth = 99999) + { + SpriteText.drawStringHorizontallyCenteredAt( + b: b, + s: s, + x: x, + y: y, + characterPosition: characterPosition, + width: width, + height: height, + alpha: alpha, + layerDepth: layerDepth, + junimoText: junimoText, + color: color != -1 ? SpriteText.getColorFromIndex(color) : null, + maxWidth: maxWidth + ); + } + /********* ** Private methods diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/StatsFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/StatsFacade.cs new file mode 100644 index 000000000..2c927606c --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/StatsFacade.cs @@ -0,0 +1,343 @@ +using System.Diagnostics.CodeAnalysis; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "IdentifierTypo", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = SuppressReasons.BaseForClarity)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class StatsFacade : Stats, IRewriteFacade + { + /********* + ** Accessors + *********/ + /**** + ** Other fields + ****/ + public new SerializableDictionary specificMonstersKilled + { + get => base.specificMonstersKilled; + } + + //started using this in 1.4 to track stats, rather than the annoying and messy uint fields above + public SerializableDictionary stat_dictionary + { + get => base.Values; + } + + /**** + ** Former uint fields + ****/ + public uint averageBedtime + { + get => base.AverageBedtime; + set => base.AverageBedtime = value; + } + + public uint beveragesMade + { + get => base.BeveragesMade; + set => base.BeveragesMade = value; + } + + public uint caveCarrotsFound + { + get => base.CaveCarrotsFound; + set => base.CaveCarrotsFound = value; + } + + public uint cheeseMade + { + get => base.CheeseMade; + set => base.CheeseMade = value; + } + + public uint chickenEggsLayed + { + get => base.ChickenEggsLayed; + set => base.ChickenEggsLayed = value; + } + + public uint copperFound + { + get => base.CopperFound; + set => base.CopperFound = value; + } + + public uint cowMilkProduced + { + get => base.CowMilkProduced; + set => base.CowMilkProduced = value; + } + + public uint cropsShipped + { + get => base.CropsShipped; + set => base.CropsShipped = value; + } + + public uint daysPlayed + { + get => base.DaysPlayed; + set => base.DaysPlayed = value; + } + + public uint diamondsFound + { + get => base.DiamondsFound; + set => base.DiamondsFound = value; + } + + public uint dirtHoed + { + get => base.DirtHoed; + set => base.DirtHoed = value; + } + + public uint duckEggsLayed + { + get => base.DuckEggsLayed; + set => base.DuckEggsLayed = value; + } + + public uint fishCaught + { + get => base.FishCaught; + set => base.FishCaught = value; + } + + public uint geodesCracked + { + get => base.GeodesCracked; + set => base.GeodesCracked = value; + } + + public uint giftsGiven + { + get => base.GiftsGiven; + set => base.GiftsGiven = value; + } + + public uint goatCheeseMade + { + get => base.GoatCheeseMade; + set => base.GoatCheeseMade = value; + } + + public uint goatMilkProduced + { + get => base.GoatMilkProduced; + set => base.GoatMilkProduced = value; + } + + public uint goldFound + { + get => base.GoldFound; + set => base.GoldFound = value; + } + + public uint goodFriends + { + get => base.GoodFriends; + set => base.GoodFriends = value; + } + + public uint individualMoneyEarned + { + get => base.IndividualMoneyEarned; + set => base.IndividualMoneyEarned = value; + } + + public uint iridiumFound + { + get => base.IridiumFound; + set => base.IridiumFound = value; + } + + public uint ironFound + { + get => base.IronFound; + set => base.IronFound = value; + } + + public uint itemsCooked + { + get => base.ItemsCooked; + set => base.ItemsCooked = value; + } + + public uint itemsCrafted + { + get => base.ItemsCrafted; + set => base.ItemsCrafted = value; + } + + public uint itemsForaged + { + get => base.ItemsForaged; + set => base.ItemsForaged = value; + } + + public uint itemsShipped + { + get => base.ItemsShipped; + set => base.ItemsShipped = value; + } + + public uint monstersKilled + { + get => base.MonstersKilled; + set => base.MonstersKilled = value; + } + + public uint mysticStonesCrushed + { + get => base.MysticStonesCrushed; + set => base.MysticStonesCrushed = value; + } + + public uint notesFound + { + get => base.NotesFound; + set => base.NotesFound = value; + } + + public uint otherPreciousGemsFound + { + get => base.OtherPreciousGemsFound; + set => base.OtherPreciousGemsFound = value; + } + + public uint piecesOfTrashRecycled + { + get => base.PiecesOfTrashRecycled; + set => base.PiecesOfTrashRecycled = value; + } + + public uint preservesMade + { + get => base.PreservesMade; + set => base.PreservesMade = value; + } + + public uint prismaticShardsFound + { + get => base.PrismaticShardsFound; + set => base.PrismaticShardsFound = value; + } + + public uint questsCompleted + { + get => base.QuestsCompleted; + set => base.QuestsCompleted = value; + } + + public uint rabbitWoolProduced + { + get => base.RabbitWoolProduced; + set => base.RabbitWoolProduced = value; + } + + public uint rocksCrushed + { + get => base.RocksCrushed; + set => base.RocksCrushed = value; + } + + public uint seedsSown + { + get => base.SeedsSown; + set => base.SeedsSown = value; + } + + public uint sheepWoolProduced + { + get => base.SheepWoolProduced; + set => base.SheepWoolProduced = value; + } + + public uint slimesKilled + { + get => base.SlimesKilled; + set => base.SlimesKilled = value; + } + + public uint stepsTaken + { + get => base.StepsTaken; + set => base.StepsTaken = value; + } + + public uint stoneGathered + { + get => base.StoneGathered; + set => base.StoneGathered = value; + } + + public uint stumpsChopped + { + get => base.StumpsChopped; + set => base.StumpsChopped = value; + } + + public uint timesFished + { + get => base.TimesFished; + set => base.TimesFished = value; + } + + public uint timesUnconscious + { + get => base.TimesUnconscious; + set => base.TimesUnconscious = value; + } + + public uint totalMoneyGifted + { + get => base.Get("totalMoneyGifted"); + set => base.Set("totalMoneyGifted", value); + } + + public uint trufflesFound + { + get => base.TrufflesFound; + set => base.TrufflesFound = value; + } + + public uint weedsEliminated + { + get => base.WeedsEliminated; + set => base.WeedsEliminated = value; + } + + + /********* + ** Public methods + *********/ + public uint getStat(string label) + { + return base.Get(label); + } + + public void incrementStat(string label, int amount) + { + base.Increment(label, amount); + } + + + + /********* + ** Private methods + *********/ + private StatsFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TemporaryAnimatedSpriteFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TemporaryAnimatedSpriteFacade.cs new file mode 100644 index 000000000..7e5ed0203 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TemporaryAnimatedSpriteFacade.cs @@ -0,0 +1,34 @@ +using System.Diagnostics.CodeAnalysis; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = SuppressReasons.MatchesOriginal)] + public class TemporaryAnimatedSpriteFacade : TemporaryAnimatedSprite, IRewriteFacade + { + /********* + ** Accessors + *********/ + public new float id + { + get => base.id; + set => base.id = (int)value; + } + + + /********* + ** Private methods + *********/ + private TemporaryAnimatedSpriteFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TerrainFeatureFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TerrainFeatureFacade.cs index 959af929c..a862933b5 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TerrainFeatureFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TerrainFeatureFacade.cs @@ -14,6 +14,22 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] public class TerrainFeatureFacade : TerrainFeature, IRewriteFacade { + /********* + ** Accessors + *********/ + public GameLocation currentLocation + { + get => base.Location; + set => base.Location = value; + } + + public Vector2 currentTileLocation + { + get => base.Tile; + set => base.Tile = value; + } + + /********* ** Public methods *********/ diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TvFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TvFacade.cs new file mode 100644 index 000000000..235dc874f --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/TvFacade.cs @@ -0,0 +1,33 @@ +using System.Diagnostics.CodeAnalysis; +using Microsoft.Xna.Framework; +using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewValley.Objects; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly. + +namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6 +{ + /// Maps Stardew Valley 1.5.6's methods to their newer form to avoid breaking older mods. + /// This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on for more info. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)] + [SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)] + public class TvFacade : TV, IRewriteFacade + { + /********* + ** Public methods + *********/ + public static TV Constructor(int which, Vector2 tile) + { + return new TV(which.ToString(), tile); + } + + + /********* + ** Private methods + *********/ + private TvFacade() + { + RewriteHelper.ThrowFakeConstructorCalled(); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/UtilityFacade.cs b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/UtilityFacade.cs index 026436047..4889eac04 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/UtilityFacade.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/UtilityFacade.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Linq; +using Microsoft.Xna.Framework; using StardewModdingAPI.Framework.ModLoading.Framework; using StardewValley; using StardewValley.Extensions; @@ -62,6 +64,12 @@ public static int numSilos() return Game1.GetNumberBuildingsConstructed("Silo"); } + public static List sparkleWithinArea(Rectangle bounds, int numberOfSparkles, Color sparkleColor, int delayBetweenSparkles = 100, int delayBeforeStarting = 0, string sparkleSound = "") + { + TemporaryAnimatedSpriteList list = Utility.getTemporarySpritesWithinArea(new[] { 10, 11 }, bounds, numberOfSparkles, sparkleColor, delayBetweenSparkles, delayBeforeStarting, sparkleSound); + return list.ToList(); + } + /********* ** Private methods diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index cea30f7a7..45514ab7b 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -16,16 +17,21 @@ using StardewValley.GameData; using StardewValley.GameData.FloorsAndPaths; using StardewValley.GameData.Movies; +using StardewValley.GameData.SpecialOrders; using StardewValley.Locations; using StardewValley.Menus; using StardewValley.Mods; +using StardewValley.Network; using StardewValley.Objects; using StardewValley.Pathfinding; +using StardewValley.Projectiles; +using StardewValley.Quests; using StardewValley.SpecialOrders; using StardewValley.SpecialOrders.Objectives; using StardewValley.SpecialOrders.Rewards; using StardewValley.TerrainFeatures; using StardewValley.Tools; +using static StardewValley.Projectiles.BasicProjectile; using SObject = StardewValley.Object; namespace StardewModdingAPI.Metadata @@ -78,7 +84,16 @@ public IEnumerable GetHandlers(bool paranoidMode, bool rewr /**** ** Stardew Valley 1.6 ****/ - // moved types + // moved types (audio) + .MapType("StardewValley.AudioCategoryWrapper", typeof(AudioCategoryWrapper)) + .MapType("StardewValley.AudioEngineWrapper", typeof(AudioEngineWrapper)) + .MapType("StardewValley.DummyAudioCategory", typeof(DummyAudioCategory)) + .MapType("StardewValley.DummyAudioEngine", typeof(DummyAudioEngine)) + .MapType("StardewValley.IAudioCategory", typeof(IAudioCategory)) + .MapType("StardewValley.IAudioEngine", typeof(IAudioEngine)) + .MapType("StardewValley.Network.NetAudio/SoundContext", typeof(SoundContext)) + + // moved types (enchantments) .MapType("StardewValley.AmethystEnchantment", typeof(AmethystEnchantment)) .MapType("StardewValley.AquamarineEnchantment", typeof(AquamarineEnchantment)) .MapType("StardewValley.ArchaeologistEnchantment", typeof(ArchaeologistEnchantment)) @@ -115,7 +130,9 @@ public IEnumerable GetHandlers(bool paranoidMode, bool rewr .MapType("StardewValley.VampiricEnchantment", typeof(VampiricEnchantment)) .MapType("StardewValley.WateringCanEnchantment", typeof(WateringCanEnchantment)) + // moved types (special orders) .MapType("StardewValley.SpecialOrder", typeof(SpecialOrder)) + .MapType("StardewValley.SpecialOrder/QuestDuration", typeof(QuestDuration)) .MapType("StardewValley.SpecialOrder/QuestState", typeof(SpecialOrderStatus)) .MapType("StardewValley.CollectObjective", typeof(CollectObjective)) @@ -136,12 +153,17 @@ public IEnumerable GetHandlers(bool paranoidMode, bool rewr .MapType("StardewValley.OrderReward", typeof(OrderReward)) .MapType("StardewValley.ResetEventReward", typeof(ResetEventReward)) - .MapType("StardewValley.IOAudioEngine", typeof(IAudioEngine)) + // moved types (other) + .MapType("WaterTiles", typeof(WaterTiles)) + .MapType("StardewValley.Game1/MusicContext", typeof(MusicContext)) .MapType("StardewValley.ModDataDictionary", typeof(ModDataDictionary)) .MapType("StardewValley.ModHooks", typeof(ModHooks)) - .MapType("StardewValley.Network.NetAudio/SoundContext", typeof(SoundContext)) + .MapType("StardewValley.Network.IWorldState", typeof(NetWorldState)) .MapType("StardewValley.PathFindController", typeof(PathFindController)) + // deleted delegates + .MapType("StardewValley.DelayedAction/delayedBehavior", typeof(Action)) + // field renames .MapFieldName(typeof(FloorPathData), "ID", nameof(FloorPathData.Id)) .MapFieldName(typeof(ModFarmType), "ID", nameof(ModFarmType.Id)) @@ -154,10 +176,13 @@ public IEnumerable GetHandlers(bool paranoidMode, bool rewr // general API changes // note: types are mapped before members, regardless of the order listed here .MapType("StardewValley.Buildings.Mill", typeof(Building)) + .MapFacade() .MapFacade() + .MapFacade() .MapFacade() .MapFacade() .MapFacade() + .MapFacade() .MapFacade() .MapFacade() .MapFacade() @@ -168,6 +193,7 @@ public IEnumerable GetHandlers(bool paranoidMode, bool rewr .MapFacade() .MapFacade() .MapFacade() + .MapFacade() .MapFacade() .MapFacade() .MapFacade() @@ -176,6 +202,7 @@ public IEnumerable GetHandlers(bool paranoidMode, bool rewr .MapFacade() .MapFacade() .MapFacade() + .MapFacade() .MapFacade() .MapFacade() .MapFacade() @@ -188,22 +215,34 @@ public IEnumerable GetHandlers(bool paranoidMode, bool rewr .MapFacade() .MapFacade() .MapFacade() + .MapFacade() + .MapFacade() .MapFacade() + .MapFacade() .MapFacade() .MapFacade() + .MapFacade() .MapFacade() .MapFacade() .MapFacade() + .MapFacade() .MapFacade() .MapFacade() .MapFacade() + .MapFacade() .MapFacade() + .MapFacade() .MapFacade() .MapFacade() + .MapFacade() .MapFacade() .MapFacade("Microsoft.Xna.Framework.Graphics.ViewportExtensions", typeof(ViewportExtensionsFacade)) .MapFacade() - .MapMethod("System.Void StardewValley.BellsAndWhistles.SpriteText::drawString(Microsoft.Xna.Framework.Graphics.SpriteBatch,System.String,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Single,System.Single,System.Boolean,System.Int32,System.String,System.Int32,StardewValley.BellsAndWhistles.SpriteText/ScrollTextAlignment)", typeof(SpriteTextFacade), nameof(SpriteTextFacade.drawString)) // may not get rewritten by the MapFacade above due to the ScrollTextAlignment enum also being de-nested in 1.6 too + + // Mono.Cecil seems to have trouble resolving rewritten signatures which include a nested type like `StardewValley.BellsAndWhistles.SpriteText/ScrollTextAlignment` + .MapMethod("System.Void StardewValley.BellsAndWhistles.SpriteText::drawString(Microsoft.Xna.Framework.Graphics.SpriteBatch,System.String,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Single,System.Single,System.Boolean,System.Int32,System.String,System.Int32,StardewValley.BellsAndWhistles.SpriteText/ScrollTextAlignment)", typeof(SpriteTextFacade), nameof(SpriteTextFacade.drawString)) + .MapMethod("System.Void StardewValley.BellsAndWhistles.SpriteText::drawStringWithScrollBackground(Microsoft.Xna.Framework.Graphics.SpriteBatch,System.String,System.Int32,System.Int32,System.String,System.Single,System.Int32,StardewValley.BellsAndWhistles.SpriteText/ScrollTextAlignment)", typeof(SpriteTextFacade), nameof(SpriteTextFacade.drawStringWithScrollBackground)) + .MapMethod("System.Void StardewValley.Projectiles.BasicProjectile::.ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Single,System.Single,System.Single,Microsoft.Xna.Framework.Vector2,System.String,System.String,System.Boolean,System.Boolean,StardewValley.GameLocation,StardewValley.Character,System.Boolean,StardewValley.Projectiles.BasicProjectile/onCollisionBehavior)", typeof(BasicProjectileFacade), nameof(BasicProjectileFacade.Constructor), new[] { typeof(int), typeof(int), typeof(int), typeof(int), typeof(float), typeof(float), typeof(float), typeof(Vector2), typeof(string), typeof(string), typeof(bool), typeof(bool), typeof(GameLocation), typeof(Character), typeof(bool), typeof(onCollisionBehavior) }) // BuildableGameLocation merged into GameLocation .MapFacade("StardewValley.Locations.BuildableGameLocation", typeof(BuildableGameLocationFacade))