diff --git a/spec/System/TestImport_spec.lua b/spec/System/TestImport_spec.lua index 58e6075cad9..1f1c294ab22 100644 --- a/spec/System/TestImport_spec.lua +++ b/spec/System/TestImport_spec.lua @@ -146,6 +146,39 @@ describe("TestImport", function() assert.is_truthy(item:BuildRaw():find("{vestigial}", 1, true)) end) + it("preserves modifier sections when an imported implicit wraps", function() + local itemData = { + id = "wrapped-implicit", + frameType = 2, + name = "Test Hat", + typeLine = "Iron Hat", + ilvl = 1, + implicitMods = { + { description = "Adds 1 to 2 Fire Damage to\nSpells" }, + { description = "+10 to Strength\n+11 to Dexterity" }, + }, + explicitMods = { { description = "+20 to maximum Life" } }, + } + -- Synthetic wrapping: one description can also contain independent effects. + for _, action in ipairs({ "import", "reload", "reimport" }) do + if action == "reload" then + loadBuildFromXML(build:SaveDB("code")) + else + build.importTab:ImportItem(itemData, "Helmet") + end + local item = build.itemsTab.items[build.itemsTab.slots.Helmet.selItemId] + for _ = 1, 2 do + assert.are.equals(3, #item.implicitModLines) + assert.are.equals("Adds 1 to 2 Fire Damage to\nSpells", item.implicitModLines[1].line) + assert.are.equals("+10 to Strength", item.implicitModLines[2].line) + assert.are.equals("+11 to Dexterity", item.implicitModLines[3].line) + assert.are.equals(1, #item.explicitModLines) + assert.are.equals("+20 to maximum Life", item.explicitModLines[1].line) + item = new("Item"):Item(item.raw) + end + end + end) + function importAndReimportWithOldJewel(shouldDelete) local oldJewel = new("Item"):Item([[Rarity: RARE TEST JEWEL diff --git a/spec/System/TestItemParse_spec.lua b/spec/System/TestItemParse_spec.lua index 15df122391c..6bcc9401a4a 100644 --- a/spec/System/TestItemParse_spec.lua +++ b/spec/System/TestItemParse_spec.lua @@ -4,6 +4,20 @@ describe("TestItemParse", function() return "Rarity: Rare\nName\n"..base.."\n"..s end + it("keeps implicit continuations inside a raw line count boundary", function() + for _, flag in ipairs({ "", "{crafted}", "{scourge}" }) do + local item = new("Item"):Item() + item:ParseRaw(raw("Implicits: 2\n" .. flag .. "Adds 1 to 2 Fire Damage to\n" .. flag .. "Spells\n+20 to maximum Life"), nil, nil, true) + assert.are.equals(1, #item.enchantModLines + #item.scourgeModLines + #item.implicitModLines) + assert.are.equals("+20 to maximum Life", item.explicitModLines[1].line) + end + + local item = new("Item"):Item() + item:ParseRaw(raw("Implicits: 1\nAdds 1 to 2 Fire Damage to\nSpells"), nil, nil, true) + assert.are.equals("Adds 1 to 2 Fire Damage to", item.implicitModLines[1].line) + assert.are.equals("Spells", item.explicitModLines[1].line) + end) + it("pastes Viscera names and implicit rolls without adding item descriptions as modifiers", function() newBuild() local cases = { diff --git a/src/Classes/ImportTab.lua b/src/Classes/ImportTab.lua index f4ad27a3e0a..ec97cf1c76a 100644 --- a/src/Classes/ImportTab.lua +++ b/src/Classes/ImportTab.lua @@ -1801,7 +1801,8 @@ function ImportTabClass:ImportItem(itemData, slotName, ignoreWeaponSwap, itemSet end -- Add and equip the new item - item:BuildAndParseRaw() + -- API descriptions above were split into raw text lines, including continuations. + item:ParseRaw(item:BuildRaw(), nil, nil, true) --ConPrintf("%s", item.raw) if item.base then local repIndex, repItem diff --git a/src/Classes/Item.lua b/src/Classes/Item.lua index 01c44c0bb50..f141f53237e 100644 --- a/src/Classes/Item.lua +++ b/src/Classes/Item.lua @@ -421,7 +421,7 @@ end ---@field modId string? -- Parse raw item data and extract item name, base type, quality, and modifiers -function ItemClass:ParseRaw(raw, rarity, highQuality) +function ItemClass:ParseRaw(raw, rarity, highQuality, implicitCountUsesRawLines) self.raw = raw self.name = "?" self.namePrefix = "" @@ -1199,8 +1199,10 @@ function ItemClass:ParseRaw(raw, rarity, highQuality) local modList, extra = modLib.parseMod(rangedLine) local nextModGroup = self.rawLines[l + 1] and self.rawLines[l + 1]:match("{modGroup:([^}]+)}") + local parsedImplicitLines = #self.enchantModLines + #self.scourgeModLines + #self.implicitModLines -- Only combine generated lines that came from the same modifier. if (not modList or extra) and self.rawLines[l + 1] + and (not implicitCountUsesRawLines or parsedImplicitLines + 1 ~= implicitLines) and modLine.modGroup == nextModGroup then -- Try to combine it with the next line local nextLine = self.rawLines[l+1]:gsub("%b{}", ""):gsub(" ?%(%l+%)","") @@ -1210,6 +1212,10 @@ function ItemClass:ParseRaw(raw, rarity, highQuality) if modList and not extra then line = line .. "\n" .. nextLine l = l + 1 + -- API imports count the consumed line separately; saved items count the combined entry. + if implicitCountUsesRawLines and parsedImplicitLines + 1 < implicitLines then + implicitLines = implicitLines - 1 + end else modList, extra = modLib.parseMod(rangedLine) end @@ -1667,6 +1673,10 @@ function ItemClass:ParseRaw(raw, rarity, highQuality) self.jewelRadiusIndex = self.jewelData.radiusIndex end self.isUnique = self.rarity == "UNIQUE" or self.rarity == "RELIC" + if implicitCountUsesRawLines then + -- Clones and saved items use the logical count, without the import-only context. + self.raw = self:BuildRaw() + end end ---@param modId string The id which will be present on the removed mod lines