From 450244fce606f4ae8bf601dc146deddf06ef8191 Mon Sep 17 00:00:00 2001 From: Mickael Cagnion Date: Wed, 11 Nov 2026 18:02:43 +0100 Subject: [PATCH] Preserve explicit modifiers after multiline implicit imports Importing an item whose implicit spans two lines can classify the following explicit modifier as implicit. API imports count both raw text lines, but the parser combines them into one entry without reducing the count. Account for consumed implicit continuations and normalize the saved text to its logical count so subsequent parses preserve modifier sections. --- spec/System/TestImport_spec.lua | 33 ++++++++++++++++++++++++++++++ spec/System/TestItemParse_spec.lua | 14 +++++++++++++ src/Classes/ImportTab.lua | 3 ++- src/Classes/Item.lua | 12 ++++++++++- 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/spec/System/TestImport_spec.lua b/spec/System/TestImport_spec.lua index 4dc73ef7b10..bffbcaa5e90 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 c6d5622d058..06e228622fc 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("Rarity", function() local item = new("Item"):Item("Rarity: Normal\nCoral Ring") assert.are.equals("NORMAL", item.rarity) diff --git a/src/Classes/ImportTab.lua b/src/Classes/ImportTab.lua index a44f91bc0aa..8eabf1997c7 100644 --- a/src/Classes/ImportTab.lua +++ b/src/Classes/ImportTab.lua @@ -1793,7 +1793,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 ff3e17392b6..e42e54bcb91 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 = "" @@ -1192,8 +1192,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+%)","") @@ -1203,6 +1205,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 @@ -1653,6 +1659,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