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; }
/// The item instance.
public Item Item { 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).
/// The item instance.
public SearchableItem(ItemType type, int id, Item item)
{
this.Type = type;
this.ID = id;
this.Item = item;
}
/// 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.InvariantCultureIgnoreCase) != -1
|| this.DisplayName.IndexOf(substring, StringComparison.InvariantCultureIgnoreCase) != -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.InvariantCultureIgnoreCase)
|| this.DisplayName.Equals(name, StringComparison.InvariantCultureIgnoreCase);
}
}
}