From 86607423916785ae7d0933436d8a755581f35b2b Mon Sep 17 00:00:00 2001 From: DaLion Date: Wed, 7 Dec 2022 18:13:17 -0300 Subject: Replaced slingshot ID check with Type check. --- src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs index 88ddfe6b..99de01b9 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs @@ -104,9 +104,10 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // weapons if (ShouldGet(ItemType.Weapon)) { - foreach (int id in this.TryLoad("Data\\weapons").Keys) + var weaponsData = this.TryLoad("Data\\weapons"); + foreach (int id in weaponsData.Keys) { - yield return this.TryCreate(ItemType.Weapon, id, p => p.ID is >= 32 and <= 34 + yield return this.TryCreate(ItemType.Weapon, id, p => weaponsData[p.ID].Split('/')[8] == "4" ? new Slingshot(p.ID) : new MeleeWeapon(p.ID) ); -- cgit From 45979c57dd350fc5c08155fd0794cf3c3519a256 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 28 Dec 2022 11:30:35 -0500 Subject: defer weapon data parsing until needed, handle invalid formats --- .../Framework/ItemRepository.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs index 99de01b9..c4619577 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs @@ -104,13 +104,18 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework // weapons if (ShouldGet(ItemType.Weapon)) { - var weaponsData = this.TryLoad("Data\\weapons"); - foreach (int id in weaponsData.Keys) + Dictionary weaponsData = this.TryLoad("Data\\weapons"); + foreach (KeyValuePair pair in weaponsData) { - yield return this.TryCreate(ItemType.Weapon, id, p => weaponsData[p.ID].Split('/')[8] == "4" - ? new Slingshot(p.ID) - : new MeleeWeapon(p.ID) - ); + string rawFields = pair.Value; + yield return this.TryCreate(ItemType.Weapon, pair.Key, p => + { + string[] fields = rawFields.Split('/'); + bool isSlingshot = fields.Length > 8 && fields[8] == "4"; + return isSlingshot + ? new Slingshot(p.ID) + : new MeleeWeapon(p.ID); + }); } } -- cgit