Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Archipelago.MultiClient.Net/DataPackage/ItemInfoResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ public interface IItemInfoResolver
/// </returns>
string GetItemName(long itemId, string game = null);

/// <summary>
/// Perform a lookup using the DataPackage sent as a source of truth to lookup a particular item name for a particular game.
/// </summary>
/// <param name="itemName">
/// Name of the item to lookup.
/// </param>
/// <param name="game">
/// The game to lookup the item name for, if null will look in the game the local player is connected to.
/// </param>
/// <returns>
/// The id of the item as a long, or -1 if no such item is found.
/// </returns>
long GetItemId(string itemName, string game = null);

/// <summary>
/// Get the name of a location from its id. Useful when receiving a packet and it is necessary to find the name of the location.
/// </summary>
Expand Down Expand Up @@ -81,6 +95,23 @@ public string GetItemName(long itemId, string game = null)
: null;
}

/// <inheritdoc/>
public long GetItemId(string itemName, string game = null)
{
if (game == null)
game = connectionInfoProvider.Game ?? "Archipelago";

if (string.IsNullOrEmpty(itemName))
return -1;

if (!cache.TryGetGameDataFromCache(game, out var dataPackage))
return -1;

return dataPackage.Items.TryGetValue(itemName, out var itemId)
? itemId
: -1;
}

/// <inheritdoc/>
public string GetLocationName(long locationId, string game = null)
{
Expand Down
17 changes: 17 additions & 0 deletions Archipelago.MultiClient.Net/Helpers/ReceivedItemsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ public interface IReceivedItemsHelper
/// </returns>
string GetItemName(long id, string game = null);

/// <summary>
/// Perform a lookup using the DataPackage sent as a source of truth to lookup a particular item name for a particular game.
/// </summary>
/// <param name="name">
/// Name of the item to lookup.
/// </param>
/// <param name="game">
/// The game to lookup the item name for, if null will look in the game the local player is connected to.
/// </param>
/// <returns>
/// The id of the item as a string, or -1 if no such item is found.
/// </returns>
long GetItemId(string name, string game = null);

/// <summary>
/// Total number of items received
/// </summary>
Expand Down Expand Up @@ -141,6 +155,9 @@ public ItemInfo DequeueItem()
/// <inheritdoc/>
public string GetItemName(long id, string game = null) => itemInfoResolver.GetItemName(id, game);

/// <inheritdoc/>
public long GetItemId(string name, string game = null) => itemInfoResolver.GetItemId(name, game);

void Socket_PacketReceived(ArchipelagoPacketBase packet)
{
switch (packet.PacketType)
Expand Down