summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release-notes.md2
-rw-r--r--src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs55
-rw-r--r--src/TrainerMod/Framework/ItemData/ISearchItem.cs21
-rw-r--r--src/TrainerMod/Framework/ItemData/SearchableObject.cs48
-rw-r--r--src/TrainerMod/Framework/ItemData/SearchableRing.cs48
-rw-r--r--src/TrainerMod/Framework/ItemData/SearchableWeapon.cs48
-rw-r--r--src/TrainerMod/TrainerMod.csproj4
7 files changed, 27 insertions, 199 deletions
diff --git a/release-notes.md b/release-notes.md
index 816c2b68..e23a1e45 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -16,6 +16,8 @@ For players:
* SMAPI no longer loads mods known to be obsolete or unneeded.
* SMAPI now lists mods in an easier-to-read format in the console.
* When the `ObjectInformation.xnb` is broken, SMAPI now prints one error to the console instead of a warning flood. (The individual issues are still listed in the log file if needed.)
+* TrainerMod's `list_items` command now shows all item types in the game. You can search specific item types like `list_items weapons`, and use `list_item_types` to see a list of types.
+* TrainerMod's `list_items` with search keywords now also searches items' translated names.
For modders:
* You can now specify minimum dependency versions in `manifest.json`.
diff --git a/src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs b/src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs
index 30c3de3b..7f4f454c 100644
--- a/src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs
+++ b/src/TrainerMod/Framework/Commands/Player/ListItemsCommand.cs
@@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using StardewModdingAPI;
-using StardewValley;
-using StardewValley.Objects;
using TrainerMod.Framework.ItemData;
namespace TrainerMod.Framework.Commands.Player
@@ -12,6 +10,13 @@ namespace TrainerMod.Framework.Commands.Player
internal class ListItemsCommand : TrainerCommand
{
/*********
+ ** Properties
+ *********/
+ /// <summary>Provides methods for searching and constructing items.</summary>
+ private readonly ItemRepository Items = new ItemRepository();
+
+
+ /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
@@ -24,12 +29,24 @@ namespace TrainerMod.Framework.Commands.Player
/// <param name="args">The command arguments.</param>
public override void Handle(IMonitor monitor, string command, ArgumentParser args)
{
- var matches = this.GetItems(args.ToArray()).ToArray();
+ // validate
+ if (!Context.IsWorldReady)
+ {
+ monitor.Log("You need to load a save to use this command.", LogLevel.Error);
+ return;
+ }
- // show matches
+ // handle
+ SearchableItem[] matches =
+ (
+ from item in this.GetItems(args.ToArray())
+ orderby item.Type.ToString(), item.Name
+ select item
+ )
+ .ToArray();
string summary = "Searching...\n";
if (matches.Any())
- monitor.Log(summary + this.GetTableString(matches, new[] { "type", "id", "name" }, val => new[] { val.Type.ToString(), val.ID.ToString(), val.Name }), LogLevel.Info);
+ monitor.Log(summary + this.GetTableString(matches, new[] { "type", "name", "id" }, val => new[] { val.Type.ToString(), val.Name, val.ID.ToString() }), LogLevel.Info);
else
monitor.Log(summary + "No items found", LogLevel.Info);
}
@@ -40,7 +57,7 @@ namespace TrainerMod.Framework.Commands.Player
*********/
/// <summary>Get all items which can be searched and added to the player's inventory through the console.</summary>
/// <param name="searchWords">The search string to find.</param>
- private IEnumerable<ISearchItem> GetItems(string[] searchWords)
+ private IEnumerable<SearchableItem> GetItems(string[] searchWords)
{
// normalise search term
searchWords = searchWords?.Where(word => !string.IsNullOrWhiteSpace(word)).ToArray();
@@ -49,33 +66,11 @@ namespace TrainerMod.Framework.Commands.Player
// find matches
return (
- from item in this.GetItems()
- let term = $"{item.ID}|{item.Type}|{item.Name}"
+ from item in this.Items.GetAll()
+ let term = $"{item.ID}|{item.Type}|{item.Name}|{item.DisplayName}"
where searchWords == null || searchWords.All(word => term.IndexOf(word, StringComparison.CurrentCultureIgnoreCase) != -1)
select item
);
}
-
- /// <summary>Get all items which can be searched and added to the player's inventory through the console.</summary>
- private IEnumerable<ISearchItem> GetItems()
- {
- // objects
- foreach (int id in Game1.objectInformation.Keys)
- {
- ISearchItem obj = id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange
- ? new SearchableRing(id)
- : (ISearchItem)new SearchableObject(id);
- if (obj.IsValid)
- yield return obj;
- }
-
- // weapons
- foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\weapons").Keys)
- {
- ISearchItem weapon = new SearchableWeapon(id);
- if (weapon.IsValid)
- yield return weapon;
- }
- }
}
}
diff --git a/src/TrainerMod/Framework/ItemData/ISearchItem.cs b/src/TrainerMod/Framework/ItemData/ISearchItem.cs
deleted file mode 100644
index db30da77..00000000
--- a/src/TrainerMod/Framework/ItemData/ISearchItem.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-namespace TrainerMod.Framework.ItemData
-{
- /// <summary>An item that can be searched and added to the player's inventory through the console.</summary>
- internal interface ISearchItem
- {
- /*********
- ** Accessors
- *********/
- /// <summary>Whether the item is valid.</summary>
- bool IsValid { get; }
-
- /// <summary>The item ID.</summary>
- int ID { get; }
-
- /// <summary>The item name.</summary>
- string Name { get; }
-
- /// <summary>The item type.</summary>
- ItemType Type { get; }
- }
-} \ No newline at end of file
diff --git a/src/TrainerMod/Framework/ItemData/SearchableObject.cs b/src/TrainerMod/Framework/ItemData/SearchableObject.cs
deleted file mode 100644
index 7e44a315..00000000
--- a/src/TrainerMod/Framework/ItemData/SearchableObject.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using StardewValley;
-
-namespace TrainerMod.Framework.ItemData
-{
- /// <summary>An object that can be searched and added to the player's inventory through the console.</summary>
- internal class SearchableObject : ISearchItem
- {
- /*********
- ** Properties
- *********/
- /// <summary>The underlying item.</summary>
- private readonly Item Item;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Whether the item is valid.</summary>
- public bool IsValid => this.Item != null && this.Item.Name != "Broken Item";
-
- /// <summary>The item ID.</summary>
- public int ID => this.Item.parentSheetIndex;
-
- /// <summary>The item name.</summary>
- public string Name => this.Item.Name;
-
- /// <summary>The item type.</summary>
- public ItemType Type => ItemType.Object;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Construct an instance.</summary>
- /// <param name="id">The item ID.</param>
- public SearchableObject(int id)
- {
- try
- {
- this.Item = new Object(id, 1);
- }
- catch
- {
- // invalid
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/TrainerMod/Framework/ItemData/SearchableRing.cs b/src/TrainerMod/Framework/ItemData/SearchableRing.cs
deleted file mode 100644
index 20b6aef2..00000000
--- a/src/TrainerMod/Framework/ItemData/SearchableRing.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using StardewValley.Objects;
-
-namespace TrainerMod.Framework.ItemData
-{
- /// <summary>A ring that can be searched and added to the player's inventory through the console.</summary>
- internal class SearchableRing : ISearchItem
- {
- /*********
- ** Properties
- *********/
- /// <summary>The underlying item.</summary>
- private readonly Ring Ring;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Whether the item is valid.</summary>
- public bool IsValid => this.Ring != null;
-
- /// <summary>The item ID.</summary>
- public int ID => this.Ring.parentSheetIndex;
-
- /// <summary>The item name.</summary>
- public string Name => this.Ring.Name;
-
- /// <summary>The item type.</summary>
- public ItemType Type => ItemType.Ring;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Construct an instance.</summary>
- /// <param name="id">The ring ID.</param>
- public SearchableRing(int id)
- {
- try
- {
- this.Ring = new Ring(id);
- }
- catch
- {
- // invalid
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/TrainerMod/Framework/ItemData/SearchableWeapon.cs b/src/TrainerMod/Framework/ItemData/SearchableWeapon.cs
deleted file mode 100644
index 70d659ee..00000000
--- a/src/TrainerMod/Framework/ItemData/SearchableWeapon.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using StardewValley.Tools;
-
-namespace TrainerMod.Framework.ItemData
-{
- /// <summary>A weapon that can be searched and added to the player's inventory through the console.</summary>
- internal class SearchableWeapon : ISearchItem
- {
- /*********
- ** Properties
- *********/
- /// <summary>The underlying item.</summary>
- private readonly MeleeWeapon Weapon;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Whether the item is valid.</summary>
- public bool IsValid => this.Weapon != null;
-
- /// <summary>The item ID.</summary>
- public int ID => this.Weapon.initialParentTileIndex;
-
- /// <summary>The item name.</summary>
- public string Name => this.Weapon.Name;
-
- /// <summary>The item type.</summary>
- public ItemType Type => ItemType.Weapon;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>Construct an instance.</summary>
- /// <param name="id">The weapon ID.</param>
- public SearchableWeapon(int id)
- {
- try
- {
- this.Weapon = new MeleeWeapon(id);
- }
- catch
- {
- // invalid
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/TrainerMod/TrainerMod.csproj b/src/TrainerMod/TrainerMod.csproj
index 8e4e2b2e..332833df 100644
--- a/src/TrainerMod/TrainerMod.csproj
+++ b/src/TrainerMod/TrainerMod.csproj
@@ -83,11 +83,7 @@
<Compile Include="Framework\Commands\World\SetDayCommand.cs" />
<Compile Include="Framework\Commands\World\SetTimeCommand.cs" />
<Compile Include="Framework\Commands\World\FreezeTimeCommand.cs" />
- <Compile Include="Framework\ItemData\ISearchItem.cs" />
<Compile Include="Framework\ItemData\ItemType.cs" />
- <Compile Include="Framework\ItemData\SearchableObject.cs" />
- <Compile Include="Framework\ItemData\SearchableRing.cs" />
- <Compile Include="Framework\ItemData\SearchableWeapon.cs" />
<Compile Include="Framework\Commands\ITrainerCommand.cs" />
<Compile Include="Framework\ItemData\SearchableItem.cs" />
<Compile Include="Framework\ItemRepository.cs" />