Skip to content
Closed
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
40 changes: 40 additions & 0 deletions spec/System/TestItemVariants_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -602,3 +602,43 @@ describe("Versioned item variants", function()
end)
end)
end)

describe("Runeforging base variants from the unique database", function()
local function uniqueList()
while main.uniqueDB.loading do
runCallback("OnFrame")
end
return main.uniqueDB.list
end

it("injects the runeforging bases into a unique that declares none itself", function()
local item = uniqueList()["Wanderlust, Wrapped Sandals"]
assert.is_not_nil(item)
assert.same({ "Regular Base", "Runeforged", "Runemastered" }, item.baseList)
assert.equals(1, item.selectedBase)
assert.equals("Wrapped Sandals", item.baseName)
assert.same({ [1] = true }, item.baseLines["Wrapped Sandals"].baseVariantList)
assert.same({ [2] = true }, item.baseLines["Runeforged Wrapped Sandals"].baseVariantList)
assert.same({ [3] = true }, item.baseLines["Runemastered Wrapped Sandals"].baseVariantList)
end)

it("keeps the injected bases selectable through a raw round trip", function()
local item = new("Item"):Item(uniqueList()["Wanderlust, Wrapped Sandals"].raw)
assert.same({ "Regular Base", "Runeforged", "Runemastered" }, item.baseList)
item.selectedBase = 3
item:BuildAndParseRaw()
assert.equals("Runemastered Wrapped Sandals", item.baseName)
end)

it("injects the runeforging bases into every eligible unique", function()
local missing = { }
for name, item in pairs(uniqueList()) do
local baseName = item.baseName
if baseName and not item.baseList
and (data.itemBases["Runeforged " .. baseName] or data.itemBases["Runemastered " .. baseName]) then
table.insert(missing, name)
end
end
assert.same({ }, missing)
end)
end)
6 changes: 4 additions & 2 deletions src/Modules/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ function main:Init()
if newItem.base then
local baseBase = newItem.baseName
-- uniques with base variants are skipped as they can be handled manually
local hasBaseVariants = newItem.baseLines and not not next(newItem.baseLines)
-- baseLines always contains the item's own base, so the item only declares
-- base variants of its own when a "Base Variant:" line filled baseList
local hasBaseVariants = newItem.baseList and not not next(newItem.baseList)
if newItem.rarity == "UNIQUE" and not hasBaseVariants then
-- look for alternate runeforging bases
local bases = { { variantName = "Regular Base", baseName = baseBase } }
Expand All @@ -170,7 +172,7 @@ function main:Init()
table.insert(bases, { variantName = "Runemastered", baseName = "Runemastered " .. baseBase })
end
if #bases > 1 then
newItem.baseList = newItem.baseList ?? {}
newItem.baseList = { }
local baseLines = {}
-- Add variants for each base
for _, base in ipairs(bases) do
Expand Down