using System; using StardewValley; namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.ItemData { /// A game item with metadata. internal class SearchableItem { /********* ** Accessors *********/ /// The item type. public ItemType Type { get; } /// 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; } /// The item's default name. public string Name => this.Item.Name; /// The item's display name for the current language. public string DisplayName => this.Item.DisplayName; /********* ** Public methods *********/ /// Construct an instance. /// The item type. /// The unique ID (if different from the item's parent sheet index). /// Create an item instance. public SearchableItem(ItemType type, int id, Func createItem) { this.Type = type; this.ID = id; this.CreateItem = () => createItem(this); this.Item = createItem(this); } /// Get whether the item name contains a case-insensitive substring. /// The substring to find. public bool NameContains(string substring) { return this.Name.IndexOf(substring, StringComparison.OrdinalIgnoreCase) != -1 || this.DisplayName.IndexOf(substring, StringComparison.OrdinalIgnoreCase) != -1; } /// Get whether the item name is exactly equal to a case-insensitive string. /// The substring to find. public bool NameEquivalentTo(string name) { return this.Name.Equals(name, StringComparison.OrdinalIgnoreCase) || this.DisplayName.Equals(name, StringComparison.OrdinalIgnoreCase); } } }