summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-12-28 11:30:35 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-12-28 11:30:35 -0500
commit45979c57dd350fc5c08155fd0794cf3c3519a256 (patch)
tree498112ba928d88039debbbc1cbc124a97ba2ea11
parent86607423916785ae7d0933436d8a755581f35b2b (diff)
downloadSMAPI-45979c57dd350fc5c08155fd0794cf3c3519a256.tar.gz
SMAPI-45979c57dd350fc5c08155fd0794cf3c3519a256.tar.bz2
SMAPI-45979c57dd350fc5c08155fd0794cf3c3519a256.zip
defer weapon data parsing until needed, handle invalid formats
-rw-r--r--src/SMAPI.Mods.ConsoleCommands/Framework/ItemRepository.cs17
1 files changed, 11 insertions, 6 deletions
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<int, string>("Data\\weapons");
- foreach (int id in weaponsData.Keys)
+ Dictionary<int, string> weaponsData = this.TryLoad<int, string>("Data\\weapons");
+ foreach (KeyValuePair<int, string> 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);
+ });
}
}