Skip to content

Commit

Permalink
show mod which added the item in item lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Mar 19, 2024
1 parent 4393837 commit eb22156
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 1 deletion.
8 changes: 8 additions & 0 deletions LookupAnything/Framework/Lookups/Items/ItemSubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Pathoschild.Stardew.LookupAnything.Framework.DebugFields;
using Pathoschild.Stardew.LookupAnything.Framework.Fields;
using Pathoschild.Stardew.LookupAnything.Framework.Models;
using StardewModdingAPI;
using StardewModdingAPI.Utilities;
using StardewValley;
using StardewValley.Buildings;
Expand Down Expand Up @@ -131,6 +132,13 @@ public override IEnumerable<ICustomField> GetData()
}
}

// show item ID
{
IModInfo? fromMod = this.GameHelper.TryGetModFromItemId(item.ItemId);
if (fromMod != null)
yield return new GenericField(I18n.Item_CustomItem(), I18n.Item_CustomItem_Summary(modName: fromMod.Manifest.Name));
}

// don't show data for dead crop
if (isDeadCrop)
{
Expand Down
34 changes: 34 additions & 0 deletions LookupAnything/GameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ internal class GameHelper
/// <summary>Encapsulates logging to the console.</summary>
private readonly IMonitor Monitor;

/// <summary>The SMAPI API for fetching metadata about loaded mods.</summary>
private readonly IModRegistry ModRegistry;

/// <summary>The cached item data filtered to <see cref="ItemRegistry.type_object"/> items.</summary>
private Lazy<SearchableItem[]> Objects;

Expand Down Expand Up @@ -83,6 +86,7 @@ public GameHelper(Metadata metadata, IMonitor monitor, IModRegistry modRegistry,
{
this.Metadata = metadata;
this.Monitor = monitor;
this.ModRegistry = modRegistry;
this.WorldItemScanner = new WorldItemScanner(reflection);

this.CustomFarmingRedux = new CustomFarmingReduxIntegration(modRegistry, this.Monitor);
Expand Down Expand Up @@ -457,6 +461,36 @@ public bool CanHaveQuality(Item item)
return true;
}

/// <summary>Get the mod which added an item, if it follows the <a href="https://stardewvalleywiki.com/Modding:Common_data_field_types#Unique_string_ID">unique string item ID convention</a>.</summary>
/// <param name="itemId">The unqualified item ID to parse.</param>
public IModInfo? TryGetModFromItemId(string itemId)
{
// The unique string ID convention is `{mod id}_{item id}`, but both the mod ID and item ID can contain
// underscores. So here we split by `_` and check every possible prefix before the final underscore to see
// if it's a valid mod ID. We take the longest match since some mods use suffixes for grouped mods, like
// `mainMod` and `mainMod_cp`.

string[] parts = itemId.Split('_');
if (parts.Length == 1)
return null;

IModInfo? mod = null;
{
string modId = parts[0];
int itemIdIndex = parts.Length - 1;
for (int i = 0; i < itemIdIndex; i++)
{
if (i != 0)
modId += '_' + parts[i];

mod = this.ModRegistry.Get(modId) ?? mod;
}
}

return mod;
}


/****
** Coordinates
****/
Expand Down
1 change: 1 addition & 0 deletions LookupAnything/docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## Upcoming release for Stardew Valley 1.6
* Updated for Stardew Valley 1.6.
_Thanks to SinZ163 for contributing some of the fixes!_
* Added mod which added a custom item to its lookup, if the mod follows the [unique string ID](https://stardewvalleywiki.com/Modding:Modder_Guide/Game_Fundamentals#Unique_string_IDs) format.
* Added more seed info for tree lookups.
* Added support for looking up NPCs in some custom mod menus (thanks to BinaryLip!).
* Improved debug field format for player stats and schedules.
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "Inhalt",
"item.loves-this": "Liebt das",
"item.likes-this": "Mag das",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "Erzeugt Farbe",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "{{name}} platziert",
"item.contents.ready": "{{name}} bereit",
"item.contents.partial": "{{name}} in {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item",
"item.contents": "Contents",
"item.loves-this": "Loves this",
"item.likes-this": "Likes this",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "Produces dye",

// values
"item.custom-item.summary": "added by {{modName}}",
"item.contents.placed": "{{name}} placed",
"item.contents.ready": "{{name}} ready",
"item.contents.partial": "{{name}} in {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "Contiene",
"item.loves-this": "Lo ama",
"item.likes-this": "Le gusta a",
Expand All @@ -299,6 +300,7 @@
"item.produces-dye": "Produce tinte",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "{{name}}",
"item.contents.ready": "{{name}} listo",
"item.contents.partial": "{{name}} en {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "Contenu",
"item.loves-this": "Adore ça",
"item.likes-this": "Apprécie ça",
Expand All @@ -301,6 +302,7 @@
"item.produces-dye": "Produit du colorant",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "{{name}} placé",
"item.contents.ready": "{{name}} prêt",
"item.contents.partial": "{{name}} in {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "Tartalom",
"item.loves-this": "Imádja",
"item.likes-this": "Szereti",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "Festéket termel",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "{{name}} lehelyezett",
"item.contents.ready": "{{name}} elkészült",
"item.contents.partial": "{{name}} elkészül {{time}} múlva",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "Contenuti",
"item.loves-this": "Lo adora",
"item.likes-this": "Piace a",
Expand All @@ -299,6 +300,7 @@
"item.produces-dye": "Produce tinta",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "{{name}} piazzato",
"item.contents.ready": "{{name}} pronto",
"item.contents.partial": "{{name}} fra {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "内容",
"item.loves-this": "これが大好きな人",
"item.likes-this": "これが好きな人",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "染色",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "設置した {{name}}",
"item.contents.ready": "{{name}}が回収可能",
"item.contents.partial": "{{time}}で{{name}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "내용물",
"item.loves-this": "사랑함",
"item.likes-this": "좋아함",
Expand All @@ -302,6 +303,7 @@
"item.produces-dye": "생산 염료",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "{{name}}이/가 들어감",
"item.contents.ready": "{{name}}이/가 준비됨",
"item.contents.partial": "{{name}}이/가 준비되기까지 {{time}} 남음.",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "Zawartość",
"item.loves-this": "Kocha to",
"item.likes-this": "Lubi to",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "Tworzy barwnik",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "{{name}} umieszczono",
"item.contents.ready": "{{name}} ukończono",
"item.contents.partial": "{{name}} za {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "Conteúdo",
"item.loves-this": "Ama isso",
"item.likes-this": "Gosta disso",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "Produz corante",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "{{name}} colocado",
"item.contents.ready": "{{name}} pronto",
"item.contents.partial": "{{name}} em {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "Содержит",
"item.loves-this": "Любят",
"item.likes-this": "Нравится",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "Производит краситель",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "содержит {{name}}",
"item.contents.ready": "{{name}} готов",
"item.contents.partial": "{{name}} через {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "รายละเอียด",
"item.loves-this": "ชอบสิ่งนี้มากๆ",
"item.likes-this": "ชอบสิ่งนี้",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "ทำสีย้อมได้",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "{{name}} วางแล้ว",
"item.contents.ready": "{{name}} พร้อมแล้ว",
"item.contents.partial": "{{name}} ใน {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "İçindekiler",
"item.loves-this": "Bunu seviyor",
"item.likes-this": "Bunu beğeniyor",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "Boya üretir",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "{{name}} yerleştirildi",
"item.contents.ready": "{{name}} hazır",
"item.contents.partial": "{{name}} içinde {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "Містить",
"item.loves-this": "Любить",
"item.likes-this": "Подобається",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "Продукує барвник",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "Містить {{name}}",
"item.contents.ready": "{{name}} готово",
"item.contents.partial": "{{name}} за {{time}}",
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
** Item > generic lookups
*********/
// labels
"item.custom-item": "Custom item", // TODO
"item.contents": "内容",
"item.loves-this": "最爱",
"item.likes-this": "喜欢",
Expand All @@ -300,6 +301,7 @@
"item.produces-dye": "产生染料",

// values
"item.custom-item.summary": "added by {{modName}}", // TODO
"item.contents.placed": "已放置{{name}}",
"item.contents.ready": "目前{{name}}",
"item.contents.partial": "{{name}}在{{time}}后完成",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Portuguese | [↻](Automate/i18n/pt.json) | [✓](ChestsAnywhere/i18n/pt.json)
Russian | [](Automate/i18n/ru.json) | [](ChestsAnywhere/i18n/ru.json) | [](DataLayers/i18n/ru.json) | [](DebugMode/i18n/ru.json) | [](FastAnimations/i18n/ru.json) | [](HorseFluteAnywhere/i18n/ru.json) | [](LookupAnything/i18n/ru.json) | [](NoclipMode/i18n/ru.json) | [](SkipIntro/i18n/ru.json) | [](SmallBeachFarm/i18n/ru.json) | [](TractorMod/i18n/ru.json)
Spanish | [](Automate/i18n/es.json) | [](ChestsAnywhere/i18n/es.json) | [](DataLayers/i18n/es.json) | [](DebugMode/i18n/es.json) | [](FastAnimations/i18n/es.json) | [](HorseFluteAnywhere/i18n/es.json) | [](LookupAnything/i18n/es.json) | [](NoclipMode/i18n/es.json) | [](SkipIntro/i18n/es.json) | [](SmallBeachFarm/i18n/es.json) | [](TractorMod/i18n/es.json)
[Thai] | [](Automate/i18n/th.json) | [](ChestsAnywhere/i18n/th.json) | [](DataLayers/i18n/th.json) | [](DebugMode/i18n/th.json) | [](FastAnimations/i18n/th.json) | [](HorseFluteAnywhere/i18n/th.json) | [](LookupAnything/i18n/th.json) | [](NoclipMode/i18n/th.json) | [](SkipIntro/i18n/th.json) | [](SmallBeachFarm/i18n/th.json) | [](TractorMod/i18n/th.json)
Turkish | [](Automate/i18n/tr.json) | [](ChestsAnywhere/i18n/tr.json) | [](DataLayers/i18n/tr.json) | [](DebugMode/i18n/tr.json) | [](FastAnimations/i18n/tr.json) | [](HorseFluteAnywhere/i18n/tr.json) | [](LookupAnything/i18n/tr.json) | [](NoclipMode/i18n/tr.json) | [](SkipIntro/i18n/tr.json) | [](SmallBeachFarm/i18n/tr.json) | [](TractorMod/i18n/tr.json)
Turkish | [](Automate/i18n/tr.json) | [](ChestsAnywhere/i18n/tr.json) | [](DataLayers/i18n/tr.json) | [](DebugMode/i18n/tr.json) | [](FastAnimations/i18n/tr.json) | [](HorseFluteAnywhere/i18n/tr.json) | [](LookupAnything/i18n/tr.json) | [](NoclipMode/i18n/tr.json) | [](SkipIntro/i18n/tr.json) | [](SmallBeachFarm/i18n/tr.json) | [](TractorMod/i18n/tr.json)
[Ukrainian] | [](Automate/i18n/uk.json) | [](ChestsAnywhere/i18n/uk.json) | [](DataLayers/i18n/uk.json) | [](DebugMode/i18n/uk.json) | [](FastAnimations/i18n/uk.json) | [](HorseFluteAnywhere/i18n/uk.json) | [](LookupAnything/i18n/uk.json) | [](NoclipMode/i18n/uk.json) | [](SkipIntro/i18n/uk.json) | [](SmallBeachFarm/i18n/uk.json) | [](TractorMod/i18n/uk.json)

[Polish]: https://www.nexusmods.com/stardewvalley/mods/3616
Expand Down

0 comments on commit eb22156

Please sign in to comment.