From e0eddd8be52befd9b35d148cd527a7c5b5dc5c63 Mon Sep 17 00:00:00 2001 From: David Camp Date: Sat, 9 Mar 2024 22:00:58 -0800 Subject: [PATCH] Now functions as intended with 1.6Alpha --- .../Controllers/MenuController.cs | 27 ++++-- .../Controllers/TimeOfDayController.cs | 12 ++- .../GreenhouseSprinklers/ModEntry.cs | 95 +++++++++++-------- .../GreenhouseSprinklers/Models/ModConfig.cs | 1 + .../GreenhouseSprinklers/manifest.json | 2 +- 5 files changed, 87 insertions(+), 50 deletions(-) diff --git a/GreenhouseSprinklers/GreenhouseSprinklers/Controllers/MenuController.cs b/GreenhouseSprinklers/GreenhouseSprinklers/Controllers/MenuController.cs index b4e71de..d42285d 100644 --- a/GreenhouseSprinklers/GreenhouseSprinklers/Controllers/MenuController.cs +++ b/GreenhouseSprinklers/GreenhouseSprinklers/Controllers/MenuController.cs @@ -1,13 +1,10 @@ using StardewModdingAPI.Events; -using StardewModdingAPI; + using StardewValley; +using StardewValley.Buildings; using StardewValley.Menus; -using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using Bpendragon.GreenhouseSprinklers.Data; + using System.Linq; -using StardewValley.Buildings; namespace Bpendragon.GreenhouseSprinklers { @@ -17,5 +14,23 @@ private void OnBuildingListChanged(object sender, BuildingListChangedEventArgs e { Monitor.Log("Building list changed"); } + + private void OnMenuChanged(object sender, MenuChangedEventArgs e) + { + if (e.OldMenu is CarpenterMenu) + { + var gh = Game1.getFarm().buildings.OfType().FirstOrDefault(); + if (gh.buildingType.Value.StartsWith("GreenhouseSprinklers")) + { + gh.buildingType.Set("Greenhouse"); + + if (Config.ShowVisualUpgrades) + { + Monitor.Log("Invalidating Texture Cache after leaving Robin's Menu"); + Helper.GameContent.InvalidateCache("Buildings/Greenhouse"); + }//invalidate the cache after leaving robin's menu, forcing load of new sprite if applicable. + } + } + } } } diff --git a/GreenhouseSprinklers/GreenhouseSprinklers/Controllers/TimeOfDayController.cs b/GreenhouseSprinklers/GreenhouseSprinklers/Controllers/TimeOfDayController.cs index fca3a14..6c5ade9 100644 --- a/GreenhouseSprinklers/GreenhouseSprinklers/Controllers/TimeOfDayController.cs +++ b/GreenhouseSprinklers/GreenhouseSprinklers/Controllers/TimeOfDayController.cs @@ -1,9 +1,8 @@ -using StardewModdingAPI.Events; -using StardewModdingAPI; -using StardewValley.Buildings; +using StardewModdingAPI; +using StardewModdingAPI.Events; using StardewValley; +using StardewValley.Buildings; using System.Linq; -using Bpendragon.GreenhouseSprinklers.Data; namespace Bpendragon.GreenhouseSprinklers { @@ -31,6 +30,11 @@ internal void OnDayEnding(object sender, DayEndingEventArgs e) Monitor.Log($"OnDayEnding hit. Greenhouse Level {GetUpgradeLevel(gh)}"); AddLetterIfNeeded(GetUpgradeLevel(gh)); + if (gh.buildingType.Value.StartsWith("GreenhouseSprinklers")) + { + gh.buildingType.Set("Greenhouse"); + } + Monitor.Log("Day ending"); if (GetUpgradeLevel(gh) >= 2) //run these checks before we check for upgrades { diff --git a/GreenhouseSprinklers/GreenhouseSprinklers/ModEntry.cs b/GreenhouseSprinklers/GreenhouseSprinklers/ModEntry.cs index 0e5ccce..94f787e 100644 --- a/GreenhouseSprinklers/GreenhouseSprinklers/ModEntry.cs +++ b/GreenhouseSprinklers/GreenhouseSprinklers/ModEntry.cs @@ -1,27 +1,18 @@ using Bpendragon.GreenhouseSprinklers.Data; - +using Force.DeepCloner; using GreenhouseSprinklers.APIs; - using HarmonyLib; - +using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI; using StardewModdingAPI.Events; - using StardewValley; -using StardewValley.Objects; using StardewValley.Buildings; +using StardewValley.Delegates; +using StardewValley.GameData.Buildings; +using StardewValley.Objects; using StardewValley.TerrainFeatures; - -using System; using System.Collections.Generic; using System.Linq; -using Bpendragon.GreenhouseSprinklers.Patches; -using Microsoft.Xna.Framework.Graphics; -using StardewValley.GameData.Shops; -using StardewValley.GameData.Buildings; -using StardewValley.Delegates; -using StardewValley.ItemTypeDefinitions; -using Force.DeepCloner; namespace Bpendragon.GreenhouseSprinklers { @@ -50,14 +41,6 @@ public override void Entry(IModHelper helper) Config = Helper.ReadConfig(); SetBuildMaterials(); - //Set up harmony to patch the Building.upgrade function - BuildingPatches.Initialize(Monitor, Helper, Config); - var harmony = new Harmony(ModManifest.UniqueID); - harmony.Patch( - original: AccessTools.Method(typeof(Building), nameof(Building.dayUpdate)), - prefix: new HarmonyMethod(typeof(BuildingPatches), nameof(BuildingPatches.Upgrade_Prefix)) - ); - helper.ConsoleCommands.Add("ghs_setlevel", "Sets the level for the greenhouse.\n\nUsage: ghs_setlevel \n- value: integer between 0 and 3 inclusive", SetGHLevel); helper.ConsoleCommands.Add("ghs_getlevel", "Returns the level for the greenhouse.\n\nUsage: ghs_setlevel", GetGHLevel); helper.ConsoleCommands.Add("ghs_waternow", "Debug command to force watering the greenhouse (and farm if level 3 unlocked).\n\nUsage: ghs_waternow", WaterNow); @@ -66,7 +49,7 @@ public override void Entry(IModHelper helper) helper.Events.GameLoop.DayStarted += OnDayStart; helper.Events.GameLoop.DayEnding += OnDayEnding; helper.Events.GameLoop.SaveLoaded += OnLoad; - //helper.Events.Display.MenuChanged += OnMenuChanged; + helper.Events.Display.MenuChanged += OnMenuChanged; helper.Events.GameLoop.GameLaunched += OnGameLaunched; helper.Events.GameLoop.Saved += OnSaveCompleted; helper.Events.Content.AssetRequested += this.OnAssetRequested; @@ -257,11 +240,6 @@ internal bool CheckForUpgrade(string[] query, GameStateQueryContext context) private void OnAssetRequested(object sender, AssetRequestedEventArgs e) { - if (e.NameWithoutLocale.IsEquivalentTo("Content/Buildings")) - { - - } - if (Context.IsWorldReady && e.Name.IsEquivalentTo("Buildings/Greenhouse")) { var gh = Game1.getFarm().buildings.OfType().FirstOrDefault(); @@ -303,24 +281,63 @@ private void OnAssetRequested(object sender, AssetRequestedEventArgs e) { var dict = data.AsDictionary(); - BuildingData bd = dict.Data["Greenhouse"].DeepClone(); + BuildingData bd1 = dict.Data["Greenhouse"].DeepClone(); + BuildingData bd2 = dict.Data["Greenhouse"].DeepClone(); + BuildingData bd3 = dict.Data["Greenhouse"].DeepClone(); + bd1.Name = "Greenhouse Sprinkler Upgrade"; - bd.Name = "Greenhouse Sprinkler Upgrade"; - bd.Texture = "Buildings\\Greenhouse"; - bd.Description = I18n.CarpenterShop_FirstUpgradeDescription(); - bd.Builder = "Robin"; - bd.BuildCondition = $"GreenHouseSprinklers.BuildCondition 1"; - bd.BuildingToUpgrade = "Greenhouse"; - bd.BuildCost = cost.FirstUpgrade.Gold; - bd.BuildMaterials = new() + bd1.Texture = "Buildings\\Greenhouse"; + bd1.Description = I18n.CarpenterShop_FirstUpgradeDescription(); + bd1.Builder = "Robin"; + bd1.BuildCondition = $"GreenHouseSprinklers.BuildCondition 1"; + bd1.BuildingToUpgrade = "Greenhouse"; + bd1.BuildCost = cost.FirstUpgrade.Gold; + bd1.BuildDays = Config.BuildDays; + bd1.BuildMaterials = new() { new() { ItemId = $"(O){(int)cost.FirstUpgrade.Sprinkler}", Amount = cost.FirstUpgrade.SprinklerCount }, new() { ItemId = "(O)787", Amount = cost.FirstUpgrade.Batteries } }; - bd.ModData = new() { { "Bpendragon.GreenhouseSprinklers.GHLevel", "1" } }; + bd1.ModData = new() { { "Bpendragon.GreenhouseSprinklers.GHLevel", "1" } }; + + dict.Data.Add("GreenhouseSprinklers.Upgrade1", bd1); + + //Upgrade 2 + bd2.Name = "Greenhouse Sprinkler Upgrade 2"; + bd2.Texture = "Buildings\\Greenhouse"; + bd2.Description = I18n.CarpenterShop_SecondUpgradeDescription(); + bd2.Builder = "Robin"; + bd2.BuildCondition = $"GreenHouseSprinklers.BuildCondition 2"; + bd2.BuildingToUpgrade = "Greenhouse"; + bd2.BuildCost = cost.SecondUpgrade.Gold; + bd2.BuildDays = Config.BuildDays; + bd2.BuildMaterials = new() + { + new() { ItemId = $"(O){(int)cost.SecondUpgrade.Sprinkler}", Amount = cost.SecondUpgrade.SprinklerCount }, + new() { ItemId = "(O)787", Amount = cost.SecondUpgrade.Batteries } + }; + bd2.ModData = new() { { "Bpendragon.GreenhouseSprinklers.GHLevel", "2" } }; + + dict.Data.Add("GreenhouseSprinklers.Upgrade2", bd2); + + //Upgrade 3 + bd3.Name = "Greenhouse Sprinkler Upgrade 3"; + bd3.Texture = "Buildings\\Greenhouse"; + bd3.Description = I18n.CarpenterShop_FinalUpgradeDescription(); + bd3.Builder = "Robin"; + bd3.BuildCondition = $"GreenHouseSprinklers.BuildCondition 3"; + bd3.BuildingToUpgrade = "Greenhouse"; + bd3.BuildCost = cost.FinalUpgrade.Gold; + bd3.BuildDays = Config.BuildDays; + bd3.BuildMaterials = new() + { + new() { ItemId = $"(O){(int)cost.FinalUpgrade.Sprinkler}", Amount = cost.FinalUpgrade.SprinklerCount }, + new() { ItemId = "(O)787", Amount = cost.FinalUpgrade.Batteries } + }; + bd3.ModData = new() { { "Bpendragon.GreenhouseSprinklers.GHLevel", "3" } }; - dict.Data.Add("GreenhouseSprinklers.Upgrade1", bd); + dict.Data.Add("GreenhouseSprinklers.Upgrade3", bd3); }); } diff --git a/GreenhouseSprinklers/GreenhouseSprinklers/Models/ModConfig.cs b/GreenhouseSprinklers/GreenhouseSprinklers/Models/ModConfig.cs index 08f1d85..02bd6d9 100644 --- a/GreenhouseSprinklers/GreenhouseSprinklers/Models/ModConfig.cs +++ b/GreenhouseSprinklers/GreenhouseSprinklers/Models/ModConfig.cs @@ -24,6 +24,7 @@ class ModConfig public bool ShowVisualUpgrades { get; set; } = true; public bool WaterSandOnBeachFarm { get; set; } = true; public int MaxNumberOfUpgrades { get; set; } = 3; + public int BuildDays { get; set; } = 3; public List DifficultySettings = new() { diff --git a/GreenhouseSprinklers/GreenhouseSprinklers/manifest.json b/GreenhouseSprinklers/GreenhouseSprinklers/manifest.json index 16620f1..5ff6407 100644 --- a/GreenhouseSprinklers/GreenhouseSprinklers/manifest.json +++ b/GreenhouseSprinklers/GreenhouseSprinklers/manifest.json @@ -1,7 +1,7 @@ { "Name": "Greenhouse Sprinklers", "Author": "Bpendragon", - "Version": "3.0.0-Alpha-20240309-1", + "Version": "3.0.0-alpha-20240309-2", "Description": "Pay Robin off to add automatic sprinklers to the greenhouse, allowing 100% utilization", "UniqueID": "Bpendragon.GreenhouseSprinklers", "EntryDll": "GreenhouseSprinklers.dll",