Skip to content

Commit ce2fc96

Browse files
author
LocalIdentity
committed
Various fixes
Corrected fallback scalar argument handling. Preserved existing volatile rolls when editing implicits. Correctly filters unscalable ranged modifiers. Displays scaled fixed-value modifiers correctly. Consolidated duplicated label and implicit-control logic. Found and fixed an additional tab-state bug for items whose implicits cannot be changed.
1 parent a509d02 commit ce2fc96

3 files changed

Lines changed: 71 additions & 69 deletions

File tree

spec/System/TestItemTools_spec.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ local applyRangeTests = {
3636
[{ "+(-25-50)% to Fire Resistance", 1.0, 1.5 }] = "+75% to Fire Resistance",
3737
[{ "+(-25-50)% to Fire Resistance", 0.0, 1.0 }] = "-25% to Fire Resistance",
3838
[{ "+(-25-50)% to Fire Resistance", 0.0, 1.5 }] = "-37% to Fire Resistance",
39+
-- Fallback scaling
40+
[{ "+(10-20) to unsupported value", 1.0, 1.0, 1.22 }] = "+24 to unsupported value",
41+
[{ "+(10-20) to unsupported value", 1.0, 1.5, 1.22 }] = "+36 to unsupported value",
3942
}
4043

4144
describe("TestItemTools", function()
@@ -46,6 +49,16 @@ describe("TestItemTools", function()
4649
end)
4750
end
4851

52+
it("detects scalability after resolving ranges", function()
53+
assert.is_true(itemLib.isModLineScalable("+(10-20) to maximum Life", 1, 1))
54+
assert.is_false(itemLib.isModLineScalable("Your Maximum Resistances are (76-80)%", 1, 1))
55+
end)
56+
57+
it("formats corrupted fixed-value modifiers", function()
58+
local modLine = { line = "Adds 1 to 59 Chaos Damage", corruptedRange = 1.22 }
59+
assert.are.equals(colorCodes.MAGIC .. "Adds 1 to 72 Chaos Damage", itemLib.formatModLine(modLine))
60+
end)
61+
4962
it("uses the displayed item slot for anoint comparison tooltips", function()
5063
if not common.classes.ItemsTab then
5164
LoadModule("Classes/ItemsTab")

src/Classes/ItemsTab.lua

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,8 +2780,13 @@ function ItemsTabClass:CorruptDisplayItem(modType)
27802780
end
27812781
end
27822782
end
2783-
for i, modLine in ipairs(item.explicitModLines) do
2784-
modLine.corruptedRange = (not addingImplicits and corruptedRanges[i] ~= 1) and corruptedRanges[i] or 1
2783+
if not addingImplicits then
2784+
for i, modLine in ipairs(item.explicitModLines) do
2785+
local corruptedRange = corruptedRanges[i]
2786+
if corruptedRange then
2787+
modLine.corruptedRange = corruptedRange ~= 1 and corruptedRange or nil
2788+
end
2789+
end
27852790
end
27862791
item:BuildAndParseRaw()
27872792
return item
@@ -2800,37 +2805,26 @@ function ItemsTabClass:CorruptDisplayItem(modType)
28002805
selectedVariant = true
28012806
end
28022807
end
2803-
-- test if a mod is scalable at all. this will let through mods that scale, but don't actually change within the corrupt range
2804-
local testScaledLine = itemLib.applyRange(mod.line, mod.range or main.defaultItemAffixQuality, mod.valueScalar or 1, 2)
2805-
if not (testScaledLine == mod.line) and (#variantIds > 0 and selectedVariant or #variantIds == 0) then
2806-
local label = ""
2808+
local modRange = mod.range or main.defaultItemAffixQuality
2809+
if itemLib.isModLineScalable(mod.line, modRange, mod.valueScalar) and (#variantIds == 0 or selectedVariant) then
2810+
local function formatLabel(corruptedRange)
2811+
local line = itemLib.applyRange(mod.line, modRange, mod.valueScalar or 1, corruptedRange)
2812+
local lines = main:WrapString("^7" .. line, 16, 430)
2813+
return table.concat(lines, "\n"), #lines
2814+
end
28072815
controls["rollRangeValue" .. i] = new("LabelControl", { "TOPLEFT", nil, "TOPLEFT" },
28082816
{ 10, 10 + offset, 200, 16 }, "^71.00")
28092817
controls["rollRangeSlider" .. i] = new("SliderControl",
28102818
{ "LEFT", controls["rollRangeValue" .. i], "RIGHT" }, { 5, 0, 80, 18 }, function(val)
28112819
corruptedRanges[i] = 0.78 + round(0.44 * val, 2) -- 0.78-1.22
28122820
controls["rollRangeValue" .. i].label = "^7" .. string.format("%.2f", corruptedRanges[i])
2813-
local label = ""
2814-
for i, line in ipairs(main:WrapString("^7" .. itemLib.applyRange(mod.line, mod.range or main.defaultItemAffixQuality, mod.valueScalar or 1, corruptedRanges[i]), 16, 430)) do
2815-
if i == 1 then
2816-
label = line
2817-
else
2818-
label = label .. "\n" .. line
2819-
end
2820-
end
2821-
controls["rollRangeLabel" .. i].label = label
2821+
controls["rollRangeLabel" .. i].label = formatLabel(corruptedRanges[i])
28222822
end)
28232823
corruptedRanges[i] = mod.corruptedRange or 1
28242824
controls["rollRangeSlider" .. i].val = ((corruptedRanges[i]) - 0.78) / 0.44
28252825
controls["rollRangeValue" .. i].label = "^7" .. string.format("%.2f", corruptedRanges[i])
2826-
for i, line in ipairs(main:WrapString("^7" .. itemLib.applyRange(mod.line, mod.range or main.defaultItemAffixQuality, mod.valueScalar or 1, corruptedRanges[i]), 16, 430)) do
2827-
if i == 1 then
2828-
label = line
2829-
else
2830-
offset = offset + 16
2831-
label = label .. "\n" .. line
2832-
end
2833-
end
2826+
local label, lineCount = formatLabel(corruptedRanges[i])
2827+
offset = offset + 16 * (lineCount - 1)
28342828
controls["rollRangeLabel" .. i] = new("LabelControl",
28352829
{ "LEFT", controls["rollRangeSlider" .. i], "RIGHT" },
28362830
{ 5, 0, 200, 16 }, label)
@@ -2844,13 +2838,19 @@ function ItemsTabClass:CorruptDisplayItem(modType)
28442838
end
28452839
explicitOffset = offset
28462840
end
2841+
local function setImplicitControlsShown(implicitNum, canChangeImplicits)
2842+
for i = 1, 4 do
2843+
local shown = canChangeImplicits and i <= implicitNum
2844+
controls["implicit" .. i].shown = shown
2845+
controls["implicit" .. i .. "Label"].shown = shown
2846+
end
2847+
controls.implicitCannotBeChangedLabel.shown = implicitNum > 0 and not canChangeImplicits
2848+
end
28472849
controls.implicits = new("ButtonControl", { "TOPLEFT", nil, "TOPLEFT" }, { 5, 5, 80, 20 }, "Implicits",
28482850
function()
28492851
local implicitNum = currentModType == "Corrupted" and 2 or 4
2850-
for i = 1, implicitNum do
2851-
controls["implicit" .. i].shown = true
2852-
controls["implicit" .. i .. "Label"].shown = true
2853-
end
2852+
local canChangeImplicits = currentModType ~= "Corrupted" or not self.displayItem.implicitsCannotBeChanged
2853+
setImplicitControlsShown(implicitNum, canChangeImplicits)
28542854
for _, i in ipairs(shownExplicits) do
28552855
controls["rollRangeLabel" .. i].shown = false
28562856
controls["rollRangeSlider" .. i].shown = false
@@ -2868,10 +2868,7 @@ function ItemsTabClass:CorruptDisplayItem(modType)
28682868
controls.rolls = new("ButtonControl", { "LEFT", controls.implicits, "RIGHT" }, { 5, 0, 80, 20 },
28692869
"Roll Ranges",
28702870
function()
2871-
for i = 1, 4 do
2872-
controls["implicit" .. i].shown = false
2873-
controls["implicit" .. i .. "Label"].shown = false
2874-
end
2871+
setImplicitControlsShown(0, false)
28752872
for _, i in ipairs(shownExplicits) do
28762873
controls["rollRangeLabel" .. i].shown = true
28772874
controls["rollRangeSlider" .. i].shown = true
@@ -2894,32 +2891,14 @@ function ItemsTabClass:CorruptDisplayItem(modType)
28942891
currentModType = "ScourgeUpside"
28952892
buildImplicitList("ScourgeUpside")
28962893
buildImplicitList("ScourgeDownside")
2897-
controls.implicit1.shown = true
2898-
controls.implicit1Label.shown = true
2899-
controls.implicit2.shown = true
2900-
controls.implicit2Label.shown = true
2901-
controls.implicit3.shown = true
2902-
controls.implicit3Label.shown = true
2903-
controls.implicitCannotBeChangedLabel.shown = false
2904-
main.popups[1].height = 103 + 20 * 3
2905-
if self.displayItem.rarity == "UNIQUE" or self.displayItem.rarity == "RELIC" then
2906-
controls.implicit4Label.shown = true
2907-
controls.implicit4.shown = true
2908-
main.popups[1].height = 103 + 20 * 4
2909-
end
2894+
local implicitNum = (self.displayItem.rarity == "UNIQUE" or self.displayItem.rarity == "RELIC") and 4 or 3
2895+
setImplicitControlsShown(implicitNum, true)
2896+
main.popups[1].height = 103 + 20 * implicitNum
29102897
buildList(controls.implicit3, controls.implicit4, "ScourgeDownside")
29112898
buildList(controls.implicit4, controls.implicit3, "ScourgeDownside")
29122899
else
29132900
currentModType = value
2914-
controls.implicit1.shown = not self.displayItem.implicitsCannotBeChanged
2915-
controls.implicit1Label.shown = not self.displayItem.implicitsCannotBeChanged
2916-
controls.implicit2.shown = not self.displayItem.implicitsCannotBeChanged
2917-
controls.implicit2Label.shown = not self.displayItem.implicitsCannotBeChanged
2918-
controls.implicit3Label.shown = false
2919-
controls.implicit3.shown = false
2920-
controls.implicit4Label.shown = false
2921-
controls.implicit4.shown = false
2922-
controls.implicitCannotBeChangedLabel.shown = self.displayItem.implicitsCannotBeChanged
2901+
setImplicitControlsShown(2, not self.displayItem.implicitsCannotBeChanged)
29232902
main.popups[1].height = 103 + 20 * 2
29242903
end
29252904
if controls.sort then

src/Modules/ItemTools.lua

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,27 @@ itemLib.influenceInfo = {
3333
}
3434
}
3535

36-
-- Apply a value scalar to the first n of any numbers present
37-
function itemLib.applyValueScalar(line, valueScalar, numbers, precision)
38-
if valueScalar and type(valueScalar) == "number" and valueScalar ~= 1 then
39-
if precision then
40-
return line:gsub("(%d+%.?%d*)", function(num)
41-
local power = 10 ^ precision
42-
local numVal = m_floor(tonumber(num) * valueScalar * power) / power
43-
return tostring(numVal)
44-
end, numbers)
45-
else
46-
return line:gsub("(%d+)([^%.])", function(num, suffix)
47-
local numVal = m_floor(num * valueScalar + 0.001)
48-
return tostring(numVal)..suffix
49-
end, numbers)
36+
-- Apply value scalars to the first n numbers present
37+
function itemLib.applyValueScalar(line, valueScalar, baseValueScalar, numbers, precision)
38+
valueScalar = type(valueScalar) == "number" and valueScalar or 1
39+
if valueScalar == 1 and (not baseValueScalar or baseValueScalar == 1) then
40+
return line
41+
end
42+
43+
local power = 10 ^ (precision or 0)
44+
local function scaleValue(num)
45+
local value = tonumber(num)
46+
if baseValueScalar and baseValueScalar ~= 1 then
47+
value = round(value * baseValueScalar * power) / power
5048
end
49+
return tostring(m_floor(value * valueScalar * power + (precision and 0 or 0.001)) / power)
50+
end
51+
if precision then
52+
return line:gsub("(%d+%.?%d*)", scaleValue, numbers)
5153
end
52-
return line
54+
return line:gsub("(%d+)([^%.])", function(num, suffix)
55+
return scaleValue(num) .. suffix
56+
end, numbers)
5357
end
5458

5559
-- precision is express a multiplier/divide and displayPrecision is expressed as decimal precision on rounding.
@@ -336,8 +340,14 @@ function itemLib.applyRange(line, range, valueScalar, baseValueScalar)
336340
end
337341
end
338342

343+
function itemLib.isModLineScalable(line, range, valueScalar)
344+
return itemLib.applyRange(line, range, valueScalar, 1) ~= itemLib.applyRange(line, range, valueScalar, 2)
345+
end
346+
339347
function itemLib.formatModLine(modLine, dbMode)
340-
local line = (not dbMode and modLine.range and itemLib.applyRange(modLine.line, modLine.range, modLine.valueScalar, modLine.corruptedRange)) or modLine.line
348+
local shouldApplyRange = not dbMode and (modLine.range or modLine.corruptedRange)
349+
local line = shouldApplyRange and itemLib.applyRange(modLine.line, modLine.range or main.defaultItemAffixQuality,
350+
modLine.valueScalar, modLine.corruptedRange) or modLine.line
341351
if line:match("^%+?0%%? ") or (line:match(" %+?0%%? ") and not line:match("0 to [1-9]")) or line:match(" 0%-0 ") or line:match(" 0 to 0 ") then -- Hack to hide 0-value modifiers
342352
return
343353
end

0 commit comments

Comments
 (0)