add support for filtering the item repo
This isn't used by SMAPI itself, but is used by some mods like Lookup Anything that copy this code.
This commit is contained in:
parent
fe25a122f4
commit
75d7c10144
|
@ -28,8 +28,10 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework
|
|||
** Public methods
|
||||
*********/
|
||||
/// <summary>Get all spawnable items.</summary>
|
||||
/// <param name="itemTypes">The item types to fetch (or null for any type).</param>
|
||||
/// <param name="includeVariants">Whether to include flavored variants like "Sunflower Honey".</param>
|
||||
[SuppressMessage("ReSharper", "AccessToModifiedClosure", Justification = "TryCreate invokes the lambda immediately.")]
|
||||
public IEnumerable<SearchableItem> GetAll()
|
||||
public IEnumerable<SearchableItem> GetAll(ItemType[] itemTypes = null, bool includeVariants = true)
|
||||
{
|
||||
//
|
||||
//
|
||||
|
@ -41,10 +43,14 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework
|
|||
//
|
||||
//
|
||||
|
||||
|
||||
IEnumerable<SearchableItem> GetAllRaw()
|
||||
{
|
||||
HashSet<ItemType> types = itemTypes?.Any() == true ? new HashSet<ItemType>(itemTypes) : null;
|
||||
bool ShouldGet(ItemType type) => types == null || types.Contains(type);
|
||||
|
||||
// get tools
|
||||
if (ShouldGet(ItemType.Tool))
|
||||
{
|
||||
for (int q = Tool.stone; q <= Tool.iridium; q++)
|
||||
{
|
||||
int quality = q;
|
||||
|
@ -60,26 +66,44 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework
|
|||
yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 1, _ => new Shears());
|
||||
yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 2, _ => new Pan());
|
||||
yield return this.TryCreate(ItemType.Tool, this.CustomIDOffset + 3, _ => new Wand());
|
||||
}
|
||||
|
||||
// clothing
|
||||
if (ShouldGet(ItemType.Clothing))
|
||||
{
|
||||
foreach (int id in this.GetShirtIds())
|
||||
yield return this.TryCreate(ItemType.Clothing, id, p => new Clothing(p.ID));
|
||||
}
|
||||
|
||||
// wallpapers
|
||||
if (ShouldGet(ItemType.Wallpaper))
|
||||
{
|
||||
for (int id = 0; id < 112; id++)
|
||||
yield return this.TryCreate(ItemType.Wallpaper, id, p => new Wallpaper(p.ID) { Category = SObject.furnitureCategory });
|
||||
}
|
||||
|
||||
// flooring
|
||||
if (ShouldGet(ItemType.Flooring))
|
||||
{
|
||||
for (int id = 0; id < 56; id++)
|
||||
yield return this.TryCreate(ItemType.Flooring, id, p => new Wallpaper(p.ID, isFloor: true) { Category = SObject.furnitureCategory });
|
||||
}
|
||||
|
||||
// equipment
|
||||
if (ShouldGet(ItemType.Boots))
|
||||
{
|
||||
foreach (int id in this.TryLoad<int, string>("Data\\Boots").Keys)
|
||||
yield return this.TryCreate(ItemType.Boots, id, p => new Boots(p.ID));
|
||||
}
|
||||
if (ShouldGet(ItemType.Hat))
|
||||
{
|
||||
foreach (int id in this.TryLoad<int, string>("Data\\hats").Keys)
|
||||
yield return this.TryCreate(ItemType.Hat, id, p => new Hat(p.ID));
|
||||
}
|
||||
|
||||
// weapons
|
||||
if (ShouldGet(ItemType.Weapon))
|
||||
{
|
||||
foreach (int id in this.TryLoad<int, string>("Data\\weapons").Keys)
|
||||
{
|
||||
yield return this.TryCreate(ItemType.Weapon, id, p => (p.ID >= 32 && p.ID <= 34)
|
||||
|
@ -87,22 +111,33 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework
|
|||
: new MeleeWeapon(p.ID)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// furniture
|
||||
if (ShouldGet(ItemType.Furniture))
|
||||
{
|
||||
foreach (int id in this.TryLoad<int, string>("Data\\Furniture").Keys)
|
||||
yield return this.TryCreate(ItemType.Furniture, id, p => Furniture.GetFurnitureInstance(p.ID));
|
||||
}
|
||||
|
||||
// craftables
|
||||
if (ShouldGet(ItemType.BigCraftable))
|
||||
{
|
||||
foreach (int id in Game1.bigCraftablesInformation.Keys)
|
||||
yield return this.TryCreate(ItemType.BigCraftable, id, p => new SObject(Vector2.Zero, p.ID));
|
||||
}
|
||||
|
||||
// objects
|
||||
if (ShouldGet(ItemType.Object) || ShouldGet(ItemType.Ring))
|
||||
{
|
||||
foreach (int id in Game1.objectInformation.Keys)
|
||||
{
|
||||
string[] fields = Game1.objectInformation[id]?.Split('/');
|
||||
|
||||
// secret notes
|
||||
if (id == 79)
|
||||
{
|
||||
if (ShouldGet(ItemType.Object))
|
||||
{
|
||||
foreach (int secretNoteId in this.TryLoad<int, string>("Data\\SecretNotes").Keys)
|
||||
{
|
||||
|
@ -114,13 +149,17 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ring
|
||||
else if (id != 801 && fields?.Length >= 4 && fields[3] == "Ring") // 801 = wedding ring, which isn't an equippable ring
|
||||
{
|
||||
if (ShouldGet(ItemType.Ring))
|
||||
yield return this.TryCreate(ItemType.Ring, id, p => new Ring(p.ID));
|
||||
}
|
||||
|
||||
// item
|
||||
else
|
||||
else if (ShouldGet(ItemType.Object))
|
||||
{
|
||||
// spawn main item
|
||||
SObject item = null;
|
||||
|
@ -135,6 +174,8 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework
|
|||
continue;
|
||||
|
||||
// flavored items
|
||||
if (includeVariants)
|
||||
{
|
||||
switch (item.Category)
|
||||
{
|
||||
// fruit products
|
||||
|
@ -244,6 +285,8 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GetAllRaw().Where(p => p != null);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue