mirror of
https://github.com/kwsch/NHSE.git
synced 2026-08-06 01:40:27 -05:00
Allow parsing of item with single parenthesised variant
This commit is contained in:
parent
cb7bc35e7b
commit
c98d96861f
|
|
@ -257,8 +257,17 @@ private static Item FinalizeItem(int requestIndex, IConfigItem config, ItemDesti
|
|||
/// <returns>Returns <see cref="Item.NO_ITEM"/> if no match found.</returns>
|
||||
public static Item GetItem(string itemName, string lang = "en")
|
||||
{
|
||||
var strings = GameInfo.GetStrings(lang).ItemDataSource;
|
||||
return GetItem(itemName, strings);
|
||||
var gStrings = GameInfo.GetStrings(lang);
|
||||
var strings = gStrings.ItemDataSource;
|
||||
var parsedItem = GetItem(itemName, strings);
|
||||
if (parsedItem != Item.NO_ITEM)
|
||||
return parsedItem;
|
||||
|
||||
if (gStrings.HasAssociatedItems(itemName, out var items))
|
||||
if (items != null && items.Count == 1)
|
||||
return new Item((ushort)items[0].Value);
|
||||
|
||||
return Item.NO_ITEM;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -226,6 +226,24 @@ public List<ComboItem> GetAssociatedItems(ushort id, out string baseItemName)
|
|||
else
|
||||
return new List<ComboItem>();
|
||||
}
|
||||
|
||||
|
||||
public bool HasAssociatedItems(string baseName, out List<ComboItem>? items)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(baseName))
|
||||
{
|
||||
items = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
baseName = baseName.Trim().ToLower();
|
||||
if (!baseName.EndsWith(" "))
|
||||
baseName += " ";
|
||||
baseName += "(";
|
||||
|
||||
items = ItemDataSource.FindAll(x => x.Text.ToLower().StartsWith(baseName));
|
||||
return items.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IRemakeString
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public static class ItemParsingTests
|
|||
[InlineData("diner sofa", 0x102D)]
|
||||
[InlineData("? block", 0x35FD)]
|
||||
[InlineData("block", 0x35FE)]
|
||||
[InlineData("dal apron", 0x2F5E)]
|
||||
public static void ParseItem(string name, ushort id)
|
||||
{
|
||||
// single
|
||||
|
|
@ -33,6 +34,18 @@ public static void ParseItem(string name, ushort id)
|
|||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("royal Crown", 0x14BB)]
|
||||
[InlineData("royal crown (red)", 0x14BB)]
|
||||
[InlineData("bug aloha shirt ", 0x223C)]
|
||||
[InlineData("quaint painting", 0xA)]
|
||||
[InlineData("(none)", Item.NONE)]
|
||||
public static void ParseAssociatedItem(string nameNoParenthesis, ushort id)
|
||||
{
|
||||
var parse = ItemParser.GetItem(nameNoParenthesis);
|
||||
parse.ItemId.Should().Be(id);
|
||||
}
|
||||
|
||||
private class ConfigWrapFake : IConfigItem
|
||||
{
|
||||
public bool WrapAllItems { get; } = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user