diff options
author | Dan Volchek <volchek2@illinois.edu> | 2018-06-10 12:13:47 -0700 |
---|---|---|
committer | Dan Volchek <volchek2@illinois.edu> | 2018-06-10 12:13:47 -0700 |
commit | bd0800f2609c14e30e8822e48323d4eb92c67bb4 (patch) | |
tree | da4e59e5d84801f2f5f263ea1d8b1defc06a0e6e /src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player | |
parent | 235d67623de648499db521606e4b9033d35388e5 (diff) | |
download | SMAPI-bd0800f2609c14e30e8822e48323d4eb92c67bb4.tar.gz SMAPI-bd0800f2609c14e30e8822e48323d4eb92c67bb4.tar.bz2 SMAPI-bd0800f2609c14e30e8822e48323d4eb92c67bb4.zip |
find item if there is exactly one exact name match
Diffstat (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player')
-rw-r--r-- | src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs index 71c3ff98..f1b573cd 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData; using StardewValley; @@ -100,6 +101,12 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player // find matching items SearchableItem[] matches = this.Items.GetAll().Where(p => p.NameContains(name)).ToArray(); + + // if exactly one item with the exact same name, use that item + SearchableItem[] exactNameMatches = matches.Where(p => p.NameEquivalentTo(name)).ToArray(); + if (exactNameMatches.Length == 1) + return exactNameMatches[0]; + switch (matches.Length) { // none found @@ -107,10 +114,6 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player monitor.Log($"There's no item with name '{name}'. You can use the 'list_items [name]' command to search for items.", LogLevel.Error); return null; - // exact match - case 1 when matches[0].NameEquivalentTo(name): - return matches[0]; - // list matches default: string options = this.GetTableString( |