diff --git a/FarmerHelper/FarmerHelper.csproj b/FarmerHelper/FarmerHelper.csproj index 4c092b49..d5769ba8 100644 --- a/FarmerHelper/FarmerHelper.csproj +++ b/FarmerHelper/FarmerHelper.csproj @@ -1,7 +1,7 @@  1.0.0 - net5.0 + net6.0 true AnyCPU;x64 diff --git a/FarmerHelper/IGenericModConfigMenuApi.cs b/FarmerHelper/IGenericModConfigMenuApi.cs index c69e6e50..eeb69f01 100644 --- a/FarmerHelper/IGenericModConfigMenuApi.cs +++ b/FarmerHelper/IGenericModConfigMenuApi.cs @@ -38,8 +38,9 @@ public interface IGenericModConfigMenuApi /// The minimum allowed value, or null to allow any. /// The maximum allowed value, or null to allow any. /// The interval of values that can be selected. + /// Get the display text to show for a value, or null to show the number as-is. /// The unique field ID for use with , or null to auto-generate a randomized ID. - void AddNumberOption(IManifest mod, Func getValue, Action setValue, Func name, Func tooltip = null, int? min = null, int? max = null, int? interval = null, string fieldId = null); + void AddNumberOption(IManifest mod, Func getValue, Action setValue, Func name, Func tooltip = null, int? min = null, int? max = null, int? interval = null, Func formatValue = null, string fieldId = null); /// Remove a mod from the config UI and delete all its options and pages. /// The mod's manifest. diff --git a/FarmerHelper/MethodPatches.cs b/FarmerHelper/MethodPatches.cs index 57e9ed56..c2622016 100644 --- a/FarmerHelper/MethodPatches.cs +++ b/FarmerHelper/MethodPatches.cs @@ -21,9 +21,7 @@ private static bool Utility_tryToPlaceItem_Prefix(GameLocation location, Item it Vector2 tileLocation = new Vector2((float)(x / 64), (float)(y / 64)); if (!location.terrainFeatures.TryGetValue(tileLocation, out TerrainFeature f) || f is not HoeDirt) return true; - Crop c = new Crop(item.ParentSheetIndex, 0, 0); - if (c == null) - return true; + Crop c = new Crop(item.ItemId, 0, 0, location); if (c.phaseDays.Count == 0 || EnoughDaysLeft(c, f as HoeDirt)) return true; __result = false; @@ -45,10 +43,8 @@ private static bool Object_placementAction_Prefix(Object __instance, GameLocatio if (location.SeedsIgnoreSeasonsHere()) return true; - - Crop c = new Crop(__instance.ParentSheetIndex, x, y); - if (c == null) - return true; + + Crop c = new Crop(__instance.ItemId, x, y, location); if (c.phaseDays.Count == 0 || EnoughDaysLeft(c, f as HoeDirt)) return true; SMonitor.Log($"Preventing planting {__instance.Name}"); @@ -61,8 +57,8 @@ private static void IClickableMenu_drawToolTip_Prefix(string hoverText, ref stri if (!Config.EnableMod || !Config.LabelLatePlanting || hoveredItem == null) return; - Crop crop = new Crop(hoveredItem.ParentSheetIndex, 0, 0); - if (crop == null || crop.phaseDays.Count == 0 || !crop.seasonsToGrowIn.Contains(Game1.currentSeason) || EnoughDaysLeft(crop, null) || (new int[] { 495, 496, 497, 498, 770 }).Contains(hoveredItem.ParentSheetIndex)) + Crop crop = new Crop(hoveredItem.ItemId, 0, 0, Game1.currentLocation); + if (crop.phaseDays.Count == 0 || !crop.GetData().Seasons.Contains(Game1.season) || EnoughDaysLeft(crop, null) || (new int[] { 495, 496, 497, 498, 770 }).Contains(hoveredItem.ParentSheetIndex)) return; hoverTitle = string.Format(SHelper.Translation.Get("too-late"), hoverTitle); @@ -81,7 +77,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi { if (terrainFeature is HoeDirt && (terrainFeature as HoeDirt).crop != null && !(terrainFeature as HoeDirt).hasPaddyCrop() && (terrainFeature as HoeDirt).state.Value == 0 && (terrainFeature as HoeDirt).crop.currentPhase.Value < (terrainFeature as HoeDirt).crop.phaseDays.Count - 1) { - logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Farm {terrainFeature.currentTileLocation.X},{terrainFeature.currentTileLocation.Y} is unwatered"); + logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Farm {terrainFeature.Tile.X},{terrainFeature.Tile.Y} is unwatered"); if (!added) { added = true; @@ -93,7 +89,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi { if (terrainFeature is HoeDirt && (terrainFeature as HoeDirt).crop != null && !(terrainFeature as HoeDirt).hasPaddyCrop() && (terrainFeature as HoeDirt).state.Value == 0 && (terrainFeature as HoeDirt).crop.currentPhase.Value < (terrainFeature as HoeDirt).crop.phaseDays.Count - 1) { - logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Greenhouse {terrainFeature.currentTileLocation.X},{terrainFeature.currentTileLocation.Y} is unwatered"); + logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Greenhouse {terrainFeature.Tile.X},{terrainFeature.Tile.Y} is unwatered"); if (!added) { added = true; @@ -111,7 +107,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi { if (terrainFeature is HoeDirt && (terrainFeature as HoeDirt).readyForHarvest() && (!Config.IgnoreFlowers || new Object((terrainFeature as HoeDirt).crop.indexOfHarvest.Value, 1, false, -1, 0).Category != -80) && (!ignoreCrops.Contains((terrainFeature as HoeDirt).crop?.indexOfHarvest.Value + ""))) { - logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Farm {terrainFeature.currentTileLocation.X},{terrainFeature.currentTileLocation.Y} is ready to harvest"); + logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Farm {terrainFeature.Tile.X},{terrainFeature.Tile.Y} is ready to harvest"); if (!added) { added = true; @@ -123,7 +119,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi { if (terrainFeature is HoeDirt && (terrainFeature as HoeDirt).readyForHarvest()) { - logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Greenhouse {terrainFeature.currentTileLocation.X},{terrainFeature.currentTileLocation.Y} is ready to harvest"); + logMessage.Add($"Crop with harvest index {(terrainFeature as HoeDirt).crop.indexOfHarvest.Value} at Greenhouse {terrainFeature.Tile.X},{terrainFeature.Tile.Y} is ready to harvest"); if (!added) { added = true; @@ -134,7 +130,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi } if (Config.WarnAboutAnimalsOutsideBeforeSleep) { - if(Game1.getFarm().Animals.Count() > 0) + if(Game1.getFarm().Animals.Any()) { logMessage.Add($"{Game1.getFarm().Animals.Count()} animals outside on farm."); question = string.Format(SHelper.Translation.Get("animals-outside"), question); @@ -145,7 +141,7 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi bool added = false; foreach (FarmAnimal animal in Game1.getFarm().Animals.Values) { - if (animal.currentProduce.Value > 0 && !animal.type.Value.Contains("Pig")) + if (animal.currentProduce.Value != null && !animal.type.Value.Contains("Pig")) { logMessage.Add($"{animal.type.Value} {animal.Name} on farm is ready to harvest"); if (!added) @@ -157,13 +153,14 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi } foreach (Building building in Game1.getFarm().buildings) { - if (building.indoors.Value is not AnimalHouse) + if (building.GetIndoors() is not AnimalHouse) continue; - foreach (FarmAnimal animal in (building.indoors.Value as AnimalHouse).animals.Values) + + foreach (FarmAnimal animal in (building.GetIndoors() as AnimalHouse).animals.Values) { - if (animal.currentProduce.Value > 0 && !animal.type.Value.Contains("Pig")) + if (animal.currentProduce.Value != null && !animal.type.Value.Contains("Pig")) { - logMessage.Add($"{animal.type.Value} {animal.Name} in {building.nameOfIndoors} is ready to harvest"); + logMessage.Add($"{animal.type.Value} {animal.Name} in {building.GetIndoorsName()} is ready to harvest"); if (!added) { @@ -193,11 +190,12 @@ private static void GameLocation_createQuestionDialogue_Prefix(ref string questi { if (building.indoors.Value is not AnimalHouse) continue; - foreach (FarmAnimal animal in (building.indoors.Value as AnimalHouse).animals.Values) + + foreach (FarmAnimal animal in (building.GetIndoors() as AnimalHouse).animals.Values) { if (!animal.wasPet.Value && !animal.wasAutoPet.Value) { - logMessage.Add($"{animal.type.Value} {animal.Name} in {building.nameOfIndoors} needs petting"); + logMessage.Add($"{animal.type.Value} {animal.Name} in {building.GetIndoorsName()} needs petting"); if (!added) { diff --git a/FarmerHelper/ModEntry.cs b/FarmerHelper/ModEntry.cs index 85165727..fae1d9ce 100644 --- a/FarmerHelper/ModEntry.cs +++ b/FarmerHelper/ModEntry.cs @@ -125,16 +125,15 @@ private void GameLoop_DayStarted(object sender, StardewModdingAPI.Events.DayStar Helper.GameContent.InvalidateCache("Data/ObjectInformation"); } - public static string[] seasons = new string[] { "spring", "summer", "fall", "winter" }; private static bool EnoughDaysLeft(Crop c, HoeDirt hoeDirt) { - if (c.seasonsToGrowIn.Contains(seasons[(Utility.getSeasonNumber(Game1.currentSeason) + 1) % 4])) + if (c.GetData().Seasons.Contains((Season)((Game1.seasonIndex + 1) % 4))) return true; if(hoeDirt is not null) { HoeDirt d = new HoeDirt(hoeDirt.state.Value, c); - d.currentLocation = hoeDirt.currentLocation; - d.currentTileLocation = hoeDirt.currentTileLocation; + d.Location = hoeDirt.Location; + d.Tile = hoeDirt.Tile; d.fertilizer.Value = hoeDirt.fertilizer.Value; AccessTools.Method(typeof(HoeDirt), "applySpeedIncreases").Invoke(d, new object[] { Game1.player }); c = d.crop; diff --git a/FarmerHelper/manifest.json b/FarmerHelper/manifest.json index 99f8298b..1ce59a1f 100644 --- a/FarmerHelper/manifest.json +++ b/FarmerHelper/manifest.json @@ -1,11 +1,11 @@ { "Name": "Farmer Helper", "Author": "aedenthorn", - "Version": "0.4.2", + "Version": "0.4.3", "Description": "Farmer Helper.", "UniqueID": "aedenthorn.FarmerHelper", "EntryDll": "FarmerHelper.dll", - "MinimumApiVersion": "3.13.0", + "MinimumApiVersion": "4.0.0", "ModUpdater": { "Repository": "StardewValleyMods", "User": "aedenthorn",