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
35 changes: 35 additions & 0 deletions spec/System/TestSearchHost_spec.lua
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
22 changes: 21 additions & 1 deletion src/Modules/Data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,7 @@ end
---@class ItemBaseTincture
---@field manaBurn? number
---@field cooldown? number
---@field buff? string[] # tincture-granted buff line(s)

---@type table<string, ItemBase>
data.itemBases = { }
Expand All @@ -1243,6 +1244,7 @@ end

---@class ItemBaseEntry
---@field label string
---@field searchFilter string
---@field name string
---@field base ItemBase

Expand All @@ -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 = { }
Expand Down
Loading