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
33 changes: 33 additions & 0 deletions spec/System/TestImport_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/System/TestItemParse_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion src/Classes/ImportTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/Classes/Item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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+%)","")
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading