diff --git a/spec/System/TestItemVariants_spec.lua b/spec/System/TestItemVariants_spec.lua index c41bc97f4c..7ddbc1c3fb 100644 --- a/spec/System/TestItemVariants_spec.lua +++ b/spec/System/TestItemVariants_spec.lua @@ -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) diff --git a/src/Modules/Main.lua b/src/Modules/Main.lua index 69c4eec866..fc4ee50c55 100644 --- a/src/Modules/Main.lua +++ b/src/Modules/Main.lua @@ -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 } } @@ -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