From 7c652b0924476cea8dc89faa30983e01c0c66fec Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 24 Oct 2020 18:26:41 -0400 Subject: update item repo to allow creating instances later --- .../Framework/ItemData/SearchableItem.cs | 12 ++- .../Framework/ItemRepository.cs | 91 ++++++++++++---------- 2 files changed, 60 insertions(+), 43 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs index d9e63126..3675a963 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs @@ -12,9 +12,12 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData /// The item type. public ItemType Type { get; } - /// The item instance. + /// A sample item instance. public Item Item { get; } + /// Create an item instance. + public Func CreateItem { get; } + /// The item's unique ID for its type. public int ID { get; } @@ -31,12 +34,13 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData /// Construct an instance. /// The item type. /// The unique ID (if different from the item's parent sheet index). - /// The item instance. - public SearchableItem(ItemType type, int id, Item item) + /// Create an item instance. + public SearchableItem(ItemType type, int id, Func createItem) { this.Type = type; this.ID = id; - this.Item = item; + this.CreateItem = () => createItem(this); + this.Item = createItem(this); } /// Get whether the item name contains a case-insensitive substring. diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs index 37f5f8d1..a96a842c 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs @@ -30,47 +30,60 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework [SuppressMessage("ReSharper", "AccessToModifiedClosure", Justification = "TryCreate invokes the lambda immediately.")] public IEnumerable GetAll() { + // + // + // Be careful about closure variable capture here! + // + // SearchableItem stores the Func to create new instances later. Loop variables passed into the + // function will be captured, so every func in the loop will use the value from the last iteration. Use the + // TryCreate(type, id, entity => item) form to avoid the issue, or create a local variable to pass in. + // + // + + IEnumerable GetAllRaw() { // get tools - for (int quality = Tool.stone; quality <= Tool.iridium; quality++) + for (int q = Tool.stone; q <= Tool.iridium; q++) { - yield return this.TryCreate(ItemType.Tool, ToolFactory.axe, () => ToolFactory.getToolFromDescription(ToolFactory.axe, quality)); - yield return this.TryCreate(ItemType.Tool, ToolFactory.hoe, () => ToolFactory.getToolFromDescription(ToolFactory.hoe, quality)); - yield return this.TryCreate(ItemType.Tool, ToolFactory.pickAxe, () => ToolFactory.getToolFromDescription(ToolFactory.pickAxe, quality)); - yield return this.TryCreate(ItemType.Tool, ToolFactory.wateringCan, () => ToolFactory.getToolFromDescription(ToolFactory.wateringCan, quality)); + int quality = q; + + yield return this.TryCreate(ItemType.Tool, ToolFactory.axe, _ => ToolFactory.getToolFromDescription(ToolFactory.axe, quality)); + yield return this.TryCreate(ItemType.Tool, ToolFactory.hoe, _ => ToolFactory.getToolFromDescription(ToolFactory.hoe, quality)); + yield return this.TryCreate(ItemType.Tool, ToolFactory.pickAxe, _ => ToolFactory.getToolFromDescription(ToolFactory.pickAxe, quality)); + yield return this.TryCreate(ItemType.Tool, ToolFactory.wateringCan, _ => ToolFactory.getToolFromDescription(ToolFactory.wateringCan, quality)); if (quality != Tool.iridium) - yield return this.TryCreate(ItemType.Tool, ToolFactory.fishingRod, () => ToolFactory.getToolFromDescription(ToolFactory.fishingRod, quality)); + yield return this.TryCreate(ItemType.Tool, ToolFactory.fishingRod, _ => ToolFactory.getToolFromDescription(ToolFactory.fishingRod, quality)); } - yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset, () => new MilkPail()); // these don't have any sort of ID, so we'll just assign some arbitrary ones - yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 1, () => new Shears()); - yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 2, () => new Pan()); - yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 3, () => new Wand()); + yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset, _ => new MilkPail()); // these don't have any sort of ID, so we'll just assign some arbitrary ones + yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 1, _ => new Shears()); + yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 2, _ => new Pan()); + yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 3, _ => new Wand()); // clothing foreach (int id in Game1.clothingInformation.Keys) - yield return this.TryCreate(ItemType.Clothing, id, () => new Clothing(id)); + yield return this.TryCreate(ItemType.Clothing, id, p => new Clothing(p.ID)); // wallpapers for (int id = 0; id < 112; id++) - yield return this.TryCreate(ItemType.Wallpaper, id, () => new Wallpaper(id) { Category = SObject.furnitureCategory }); + yield return this.TryCreate(ItemType.Wallpaper, id, p => new Wallpaper(p.ID) { Category = SObject.furnitureCategory }); // flooring for (int id = 0; id < 56; id++) - yield return this.TryCreate(ItemType.Flooring, id, () => new Wallpaper(id, isFloor: true) { Category = SObject.furnitureCategory }); + yield return this.TryCreate(ItemType.Flooring, id, p => new Wallpaper(p.ID, isFloor: true) { Category = SObject.furnitureCategory }); // equipment foreach (int id in this.TryLoad("Data\\Boots").Keys) - yield return this.TryCreate(ItemType.Boots, id, () => new Boots(id)); + yield return this.TryCreate(ItemType.Boots, id, p => new Boots(p.ID)); foreach (int id in this.TryLoad("Data\\hats").Keys) - yield return this.TryCreate(ItemType.Hat, id, () => new Hat(id)); + yield return this.TryCreate(ItemType.Hat, id, p => new Hat(p.ID)); // weapons foreach (int id in this.TryLoad("Data\\weapons").Keys) { - yield return this.TryCreate(ItemType.Weapon, id, () => (id >= 32 && id <= 34) - ? (Item)new Slingshot(id) - : new MeleeWeapon(id) + yield return this.TryCreate(ItemType.Weapon, id, p => (p.ID >= 32 && p.ID <= 34) + ? (Item)new Slingshot(p.ID) + : new MeleeWeapon(p.ID) ); } @@ -78,14 +91,14 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework foreach (int id in this.TryLoad("Data\\Furniture").Keys) { if (id == 1466 || id == 1468 || id == 1680) - yield return this.TryCreate(ItemType.Furniture, id, () => new TV(id, Vector2.Zero)); + yield return this.TryCreate(ItemType.Furniture, id, p => new TV(p.ID, Vector2.Zero)); else - yield return this.TryCreate(ItemType.Furniture, id, () => new Furniture(id, Vector2.Zero)); + yield return this.TryCreate(ItemType.Furniture, id, p => new Furniture(p.ID, Vector2.Zero)); } // craftables foreach (int id in Game1.bigCraftablesInformation.Keys) - yield return this.TryCreate(ItemType.BigCraftable, id, () => new SObject(Vector2.Zero, id)); + yield return this.TryCreate(ItemType.BigCraftable, id, p => new SObject(Vector2.Zero, p.ID)); // objects foreach (int id in Game1.objectInformation.Keys) @@ -97,7 +110,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework { foreach (int secretNoteId in this.TryLoad("Data\\SecretNotes").Keys) { - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset + secretNoteId, () => + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset + secretNoteId, _ => { SObject note = new SObject(79, 1); note.name = $"{note.name} #{secretNoteId}"; @@ -108,18 +121,18 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // ring else if (id != 801 && fields?.Length >= 4 && fields[3] == "Ring") // 801 = wedding ring, which isn't an equippable ring - yield return this.TryCreate(ItemType.Ring, id, () => new Ring(id)); + yield return this.TryCreate(ItemType.Ring, id, p => new Ring(p.ID)); // item else { // spawn main item SObject item = null; - yield return this.TryCreate(ItemType.Object, id, () => + yield return this.TryCreate(ItemType.Object, id, p => { - return item = (id == 812 // roe - ? new ColoredObject(id, 1, Color.White) - : new SObject(id, 1) + return item = (p.ID == 812 // roe + ? new ColoredObject(p.ID, 1, Color.White) + : new SObject(p.ID, 1) ); }); if (item == null) @@ -131,7 +144,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // fruit products case SObject.FruitsCategory: // wine - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 2 + id, () => new SObject(348, 1) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 2 + id, _ => new SObject(348, 1) { Name = $"{item.Name} Wine", Price = item.Price * 3, @@ -140,7 +153,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }); // jelly - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 3 + id, () => new SObject(344, 1) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 3 + id, _ => new SObject(344, 1) { Name = $"{item.Name} Jelly", Price = 50 + item.Price * 2, @@ -152,7 +165,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // vegetable products case SObject.VegetableCategory: // juice - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 4 + id, () => new SObject(350, 1) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 4 + id, _ => new SObject(350, 1) { Name = $"{item.Name} Juice", Price = (int)(item.Price * 2.25d), @@ -161,7 +174,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }); // pickled - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, () => new SObject(342, 1) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, _ => new SObject(342, 1) { Name = $"Pickled {item.Name}", Price = 50 + item.Price * 2, @@ -172,7 +185,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // flower honey case SObject.flowersCategory: - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, () => + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, _ => { SObject honey = new SObject(Vector2.Zero, 340, $"{item.Name} Honey", false, true, false, false) { @@ -189,14 +202,14 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework foreach (var pair in Game1.objectInformation) { // get input - SObject input = this.TryCreate(ItemType.Object, -1, () => new SObject(pair.Key, 1))?.Item as SObject; + SObject input = this.TryCreate(ItemType.Object, pair.Key, p => new SObject(p.ID, 1))?.Item as SObject; if (input == null || input.Category != SObject.FishCategory) continue; Color color = this.GetRoeColor(input); // yield roe SObject roe = null; - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + id, () => + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + id, _ => { roe = new ColoredObject(812, 1, color) { @@ -211,7 +224,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // aged roe if (roe != null && pair.Key != 698) // aged sturgeon roe is caviar, which is a separate item { - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + id, () => new ColoredObject(447, 1, color) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + id, _ => new ColoredObject(447, 1, color) { name = $"Aged {input.Name} Roe", Category = -27, @@ -255,13 +268,13 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework /// The item type. /// The unique ID (if different from the item's parent sheet index). /// Create an item instance. - private SearchableItem TryCreate(ItemType type, int id, Func createItem) + private SearchableItem TryCreate(ItemType type, int id, Func createItem) { try { - var item = createItem(); - item.getDescription(); // force-load item data, so it crashes here if it's invalid - return new SearchableItem(type, id, item); + var item = new SearchableItem(type, id, createItem); + item.Item.getDescription(); // force-load item data, so it crashes here if it's invalid + return item; } catch { -- cgit From f9f3db7db03e969bde33f417d66f259a3d3e6006 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 24 Oct 2020 18:28:43 -0400 Subject: add character-customization-only shirts to item repo --- docs/release-notes.md | 3 +++ .../Framework/ItemRepository.cs | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands') diff --git a/docs/release-notes.md b/docs/release-notes.md index d6b5df7a..86081c62 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -11,6 +11,9 @@ * For modders: * Fixed error when heuristically rewriting a property for a type that no longer exists. +* For the Console Commands mod: + * `player_add` can now spawn shirts normally only available during character customization. + ## 3.7.5 Released 16 October 2020 for Stardew Valley 1.4.1 or later. diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs index a96a842c..5884d28a 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs @@ -61,8 +61,25 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 3, _ => new Wand()); // clothing - foreach (int id in Game1.clothingInformation.Keys) - yield return this.TryCreate(ItemType.Clothing, id, p => new Clothing(p.ID)); + { + // items + HashSet clothingIds = new HashSet(); + foreach (int id in Game1.clothingInformation.Keys) + { + if (id < 0) + continue; // placeholder data for character customization clothing below + + clothingIds.Add(id); + yield return this.TryCreate(ItemType.Clothing, id, p => new Clothing(p.ID)); + } + + // character customization shirts (some shirts in this range have no data, but game has special logic to handle them) + for (int id = 1000; id <= 1111; id++) + { + if (!clothingIds.Contains(id)) + yield return this.TryCreate(ItemType.Clothing, id, p => new Clothing(p.ID)); + } + } // wallpapers for (int id = 0; id < 112; id++) -- cgit From 295c34d5cd03764099f2fb803113bd60361cb282 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 28 Oct 2020 18:20:41 -0400 Subject: fix a captured loop variable --- .../Framework/ItemRepository.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs index 5884d28a..c5e2b89d 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs @@ -161,7 +161,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // fruit products case SObject.FruitsCategory: // wine - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 2 + id, _ => new SObject(348, 1) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 2 + item.ParentSheetIndex, _ => new SObject(348, 1) { Name = $"{item.Name} Wine", Price = item.Price * 3, @@ -170,7 +170,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }); // jelly - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 3 + id, _ => new SObject(344, 1) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 3 + item.ParentSheetIndex, _ => new SObject(344, 1) { Name = $"{item.Name} Jelly", Price = 50 + item.Price * 2, @@ -182,7 +182,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // vegetable products case SObject.VegetableCategory: // juice - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 4 + id, _ => new SObject(350, 1) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 4 + item.ParentSheetIndex, _ => new SObject(350, 1) { Name = $"{item.Name} Juice", Price = (int)(item.Price * 2.25d), @@ -191,7 +191,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework }); // pickled - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, _ => new SObject(342, 1) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + item.ParentSheetIndex, _ => new SObject(342, 1) { Name = $"Pickled {item.Name}", Price = 50 + item.Price * 2, @@ -202,7 +202,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // flower honey case SObject.flowersCategory: - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + id, _ => + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 5 + item.ParentSheetIndex, _ => { SObject honey = new SObject(Vector2.Zero, 340, $"{item.Name} Honey", false, true, false, false) { @@ -215,7 +215,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework break; // roe and aged roe (derived from FishPond.GetFishProduce) - case SObject.sellAtFishShopCategory when id == 812: + case SObject.sellAtFishShopCategory when item.ParentSheetIndex == 812: foreach (var pair in Game1.objectInformation) { // get input @@ -226,7 +226,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // yield roe SObject roe = null; - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + id, _ => + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + item.ParentSheetIndex, _ => { roe = new ColoredObject(812, 1, color) { @@ -241,7 +241,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // aged roe if (roe != null && pair.Key != 698) // aged sturgeon roe is caviar, which is a separate item { - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + id, _ => new ColoredObject(447, 1, color) + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + item.ParentSheetIndex, _ => new ColoredObject(447, 1, color) { name = $"Aged {input.Name} Roe", Category = -27, -- cgit From 2831b1e75a4634214fd9ba4e95edcac91d9cf321 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 28 Oct 2020 18:21:33 -0400 Subject: add SearchableItem copy constructor This is for convenience in mods which copy this code; SMAPI itself doesn't use it. --- .../Framework/ItemData/SearchableItem.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/SMAPI.Mods.ConsoleCommands') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs index 3675a963..72d01eb7 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemData/SearchableItem.cs @@ -43,6 +43,16 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData this.Item = createItem(this); } + /// Construct an instance. + /// The item metadata to copy. + public SearchableItem(SearchableItem item) + { + this.Type = item.Type; + this.ID = item.ID; + this.CreateItem = item.CreateItem; + this.Item = item.Item; + } + /// Get whether the item name contains a case-insensitive substring. /// The substring to find. public bool NameContains(string substring) -- cgit From ec84ba07cc80c74ed0c997550a401def6ea24916 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 30 Oct 2020 20:46:46 -0400 Subject: apply fish pond rules for roe spawning --- docs/release-notes.md | 1 + .../Framework/ItemRepository.cs | 88 +++++++++++++++------- 2 files changed, 60 insertions(+), 29 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands') diff --git a/docs/release-notes.md b/docs/release-notes.md index 86081c62..3d131d07 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -13,6 +13,7 @@ * For the Console Commands mod: * `player_add` can now spawn shirts normally only available during character customization. + * `player_add` now applies fish pond rules for roe items. (That mainly adds Clam Roe, Sea Urchin Roe, and custom roe from mods.) ## 3.7.5 Released 16 October 2020 for Stardew Valley 1.4.1 or later. diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs index c5e2b89d..d1dd758b 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs @@ -6,6 +6,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData; using StardewValley; +using StardewValley.GameData.FishPond; using StardewValley.Menus; using StardewValley.Objects; using StardewValley.Tools; @@ -216,39 +217,48 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // roe and aged roe (derived from FishPond.GetFishProduce) case SObject.sellAtFishShopCategory when item.ParentSheetIndex == 812: - foreach (var pair in Game1.objectInformation) { - // get input - SObject input = this.TryCreate(ItemType.Object, pair.Key, p => new SObject(p.ID, 1))?.Item as SObject; - if (input == null || input.Category != SObject.FishCategory) - continue; - Color color = this.GetRoeColor(input); - - // yield roe - SObject roe = null; - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + item.ParentSheetIndex, _ => - { - roe = new ColoredObject(812, 1, color) - { - name = $"{input.Name} Roe", - preserve = { Value = SObject.PreserveType.Roe }, - preservedParentSheetIndex = { Value = input.ParentSheetIndex } - }; - roe.Price += input.Price / 2; - return roe; - }); - - // aged roe - if (roe != null && pair.Key != 698) // aged sturgeon roe is caviar, which is a separate item + this.GetRoeContextTagLookups(out HashSet simpleTags, out List> complexTags); + + foreach (var pair in Game1.objectInformation) { - yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + item.ParentSheetIndex, _ => new ColoredObject(447, 1, color) + // get input + SObject input = this.TryCreate(ItemType.Object, pair.Key, p => new SObject(p.ID, 1))?.Item as SObject; + var inputTags = input?.GetContextTags(); + if (inputTags?.Any() != true) + continue; + + // check if roe-producing fish + if (!inputTags.Any(tag => simpleTags.Contains(tag)) && !complexTags.Any(set => set.All(tag => input.HasContextTag(tag)))) + continue; + + // yield roe + SObject roe = null; + Color color = this.GetRoeColor(input); + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + item.ParentSheetIndex, _ => { - name = $"Aged {input.Name} Roe", - Category = -27, - preserve = { Value = SObject.PreserveType.AgedRoe }, - preservedParentSheetIndex = { Value = input.ParentSheetIndex }, - Price = roe.Price * 2 + roe = new ColoredObject(812, 1, color) + { + name = $"{input.Name} Roe", + preserve = { Value = SObject.PreserveType.Roe }, + preservedParentSheetIndex = { Value = input.ParentSheetIndex } + }; + roe.Price += input.Price / 2; + return roe; }); + + // aged roe + if (roe != null && pair.Key != 698) // aged sturgeon roe is caviar, which is a separate item + { + yield return this.TryCreate(ItemType.Object, this.CustomIDOffset * 7 + item.ParentSheetIndex, _ => new ColoredObject(447, 1, color) + { + name = $"Aged {input.Name} Roe", + Category = -27, + preserve = { Value = SObject.PreserveType.AgedRoe }, + preservedParentSheetIndex = { Value = input.ParentSheetIndex }, + Price = roe.Price * 2 + }); + } } } break; @@ -264,6 +274,26 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework /********* ** Private methods *********/ + /// Get optimized lookups to match items which produce roe in a fish pond. + /// A lookup of simple singular tags which match a roe-producing fish. + /// A list of tag sets which match roe-producing fish. + private void GetRoeContextTagLookups(out HashSet simpleTags, out List> complexTags) + { + simpleTags = new HashSet(); + complexTags = new List>(); + + foreach (FishPondData data in Game1.content.Load>("Data\\FishPondData")) + { + if (data.ProducedItems.All(p => p.ItemID != 812)) + continue; // doesn't produce roe + + if (data.RequiredTags.Count == 1 && !data.RequiredTags[0].StartsWith("!")) + simpleTags.Add(data.RequiredTags[0]); + else + complexTags.Add(data.RequiredTags); + } + } + /// Try to load a data file, and return empty data if it's invalid. /// The asset key type. /// The asset value type. -- cgit From a0cb83ed406fc0447e8edf00e680585005480d23 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 21 Nov 2020 14:08:04 -0500 Subject: prepare for release --- build/common.targets | 2 +- docs/release-notes.md | 10 ++++++---- src/SMAPI.Mods.ConsoleCommands/manifest.json | 4 ++-- src/SMAPI.Mods.SaveBackup/manifest.json | 4 ++-- src/SMAPI/Constants.cs | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands') diff --git a/build/common.targets b/build/common.targets index 8e687190..d8b29488 100644 --- a/build/common.targets +++ b/build/common.targets @@ -4,7 +4,7 @@ - 3.7.5 + 3.7.6 SMAPI latest diff --git a/docs/release-notes.md b/docs/release-notes.md index ac2dcce4..1115f482 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -7,13 +7,15 @@ * Migrated to Harmony 2.0 (see [_migrate to Harmony 2.0_](https://stardewvalleywiki.com/Modding:Migrate_to_Harmony_2.0) for more info). --> -## Upcoming release +## 3.7.6 +Released 21 November 2020 for Stardew Valley 1.4.1 or later. + * For players: - * Fixed error when heuristically rewriting a mod in rare cases (i.e. when it accesses a property for a type that no longer exists). - * Fixed rare 'collection was modified' error when using `harmony summary` console command in rare cases. + * Fixed error when heuristically rewriting an outdated mod in rare cases. + * Fixed rare 'collection was modified' error when using `harmony summary` console command. * For modders: - * Updated TMXTile 1.5.6 → 1.5.8 to fix exported `.tmx` files losing tile index properties. + * Updated TMXTile to 1.5.8 to fix exported `.tmx` files losing tile index properties. * For the Console Commands mod: * `player_add` can now spawn shirts normally only available during character customization. diff --git a/src/SMAPI.Mods.ConsoleCommands/manifest.json b/src/SMAPI.Mods.ConsoleCommands/manifest.json index 300350e4..ddc55a73 100644 --- a/src/SMAPI.Mods.ConsoleCommands/manifest.json +++ b/src/SMAPI.Mods.ConsoleCommands/manifest.json @@ -1,9 +1,9 @@ { "Name": "Console Commands", "Author": "SMAPI", - "Version": "3.7.5", + "Version": "3.7.6", "Description": "Adds SMAPI console commands that let you manipulate the game.", "UniqueID": "SMAPI.ConsoleCommands", "EntryDll": "ConsoleCommands.dll", - "MinimumApiVersion": "3.7.5" + "MinimumApiVersion": "3.7.6" } diff --git a/src/SMAPI.Mods.SaveBackup/manifest.json b/src/SMAPI.Mods.SaveBackup/manifest.json index d1d8ae32..0fe98909 100644 --- a/src/SMAPI.Mods.SaveBackup/manifest.json +++ b/src/SMAPI.Mods.SaveBackup/manifest.json @@ -1,9 +1,9 @@ { "Name": "Save Backup", "Author": "SMAPI", - "Version": "3.7.5", + "Version": "3.7.6", "Description": "Automatically backs up all your saves once per day into its folder.", "UniqueID": "SMAPI.SaveBackup", "EntryDll": "SaveBackup.dll", - "MinimumApiVersion": "3.7.5" + "MinimumApiVersion": "3.7.6" } diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 754ab295..88f79811 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -51,7 +51,7 @@ namespace StardewModdingAPI ** Public ****/ /// SMAPI's current semantic version. - public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.7.5"); + public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.7.6"); /// The minimum supported version of Stardew Valley. public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.4.1"); -- cgit