From 886812b570e56fac516fbdb3adb95b347b171305 Mon Sep 17 00:00:00 2001 From: AdamZ Date: Wed, 2 Sep 2026 15:27:29 -0700 Subject: [PATCH] Search for items by modifier in craft item menu. --- spec/System/TestSearchHost_spec.lua | 35 +++++++++++++++++++++++++++++ src/Modules/Data.lua | 22 +++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/spec/System/TestSearchHost_spec.lua b/spec/System/TestSearchHost_spec.lua index 5d328d504f..b365b7200e 100644 --- a/spec/System/TestSearchHost_spec.lua +++ b/spec/System/TestSearchHost_spec.lua @@ -1,4 +1,39 @@ describe("SearchHost", function() + it("searches item bases by full name and base effects", function() + local cases = { + { type = "Amulet: Talisman", search = "monkey power charge", name = "Monkey Paw Talisman (Power)" }, + { type = "Amulet: Talisman", search = "moon rite", name = "Greatwolf Talisman" }, + { type = "Amulet: Talisman", search = "fire-to-cold", name = "Avian Twins Talisman (Fire-To-Cold)" }, + } + + for _, testCase in ipairs(cases) do + local control = new("DropDownControl"):DropDownControl(nil, { 0, 0, 100, 20 }, data.itemBaseLists[testCase.type]) + for char in testCase.search:gmatch(".") do + control:OnSearchChar(char) + end + + assert.are.equal(1, control:GetMatchCount()) + assert.are.equal(testCase.name, control.list[control:DropIndexToListIndex(1)].name) + end + end) + + it("searches flask bases by buff effects", function() + local control = new("DropDownControl"):DropDownControl(nil, { 0, 0, 100, 20 }, data.itemBaseLists["Flask: Utility"]) + for char in ("res"):gmatch(".") do + control:OnSearchChar(char) + end + + local matches = { } + for index, searchInfo in ipairs(control.searchInfos) do + if searchInfo.matches then + matches[control.list[index].name] = true + end + end + assert.is_true(matches["Ruby Flask"]) + assert.is_true(matches["Sapphire Flask"]) + assert.is_true(matches["Topaz Flask"]) + end) + it("merges all overlapping ranges when word order is ignored", function() local searchHost = new("SearchHost"):SearchHost(function() return { "caster" } diff --git a/src/Modules/Data.lua b/src/Modules/Data.lua index 26afb5f4df..a1134c8791 100644 --- a/src/Modules/Data.lua +++ b/src/Modules/Data.lua @@ -1234,6 +1234,7 @@ end ---@class ItemBaseTincture ---@field manaBurn? number ---@field cooldown? number +---@field buff? string[] # tincture-granted buff line(s) ---@type table data.itemBases = { } @@ -1243,6 +1244,7 @@ end ---@class ItemBaseEntry ---@field label string +---@field searchFilter string ---@field name string ---@field base ItemBase @@ -1256,7 +1258,25 @@ for name, base in pairs(data.itemBases) do type = type .. ": " .. base.subType end data.itemBaseLists[type] = data.itemBaseLists[type] or { } - table.insert(data.itemBaseLists[type], { label = name:gsub(" %(.+%)",""), name = name, base = base }) + local label = name:gsub(" %(.+%)","") + local searchTerms = { name } + if base.implicit then + t_insert(searchTerms, base.implicit) + end + if base.enchant then + t_insert(searchTerms, base.enchant) + end + if base.flask and base.flask.buff then + for _, line in ipairs(base.flask.buff) do + t_insert(searchTerms, line) + end + end + if base.tincture and base.tincture.buff then + for _, line in ipairs(base.tincture.buff) do + t_insert(searchTerms, line) + end + end + table.insert(data.itemBaseLists[type], { label = label, searchFilter = t_concat(searchTerms, " "), name = name, base = base }) end end data.itemBaseTypeList = { }