Skip to content

Commit 420f07b

Browse files
cupkaxLocalIdentity
andauthored
Add option to allow auto-socketing timeless jewel (#10226)
* Add option to allow auto-socketing timeless jewel * Persist timeless jewel auto-socket option Save socketAllocate to the TimelessData element and restore it on load, and mark the build modified when it is toggled, matching socketFilter. The attribute is only written when the option is enabled. * Give the auto-socket option its own row in the jewel finder * Fix undo state --------- Co-authored-by: LocalIdentity <localidentity2@gmail.com>
1 parent d05f391 commit 420f07b

4 files changed

Lines changed: 91 additions & 4 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
describe("TestTimelessJewelSettings", function()
2+
before_each(function()
3+
newBuild()
4+
end)
5+
6+
-- The finder's "Socket Jewel" toggle lives in timelessData, which only reaches the
7+
-- build XML through the TimelessData element, so cover the save/load round trip.
8+
it("round trips socketAllocate through the build XML", function()
9+
build.timelessData.socketAllocate = true
10+
local xmlText = build:SaveDB("code")
11+
assert.is_truthy(xmlText:match('socketAllocate="true"'))
12+
13+
loadBuildFromXML(xmlText)
14+
assert.is_true(build.timelessData.socketAllocate)
15+
end)
16+
17+
it("omits socketAllocate from the build XML while unticked", function()
18+
build.timelessData.socketAllocate = false
19+
local xmlText = build:SaveDB("code")
20+
assert.is_nil(xmlText:match("socketAllocate"))
21+
22+
loadBuildFromXML(xmlText)
23+
assert.is_false(build.timelessData.socketAllocate)
24+
end)
25+
26+
it("records the item addition when the target socket is unallocated", function()
27+
local socketId, socketControl = next(build.itemsTab.sockets)
28+
local result = { label = "10000:", seed = 10000, total = 1 }
29+
build.spec.allocNodes[socketId] = nil
30+
build.timelessData.socketAllocate = true
31+
build.timelessData.sharedResults = {
32+
type = { id = 2, label = "Lethal Pride" },
33+
conqueror = { id = 1 },
34+
socket = { id = socketId, label = "Socket" },
35+
desiredNodes = { },
36+
}
37+
build.timelessData.searchResults = { result }
38+
local control = new("TimelessJewelListControl"):TimelessJewelListControl(nil, { 0, 0, 300, 100 }, build)
39+
local initialItemCount = #build.itemsTab.itemOrderList
40+
build.itemsTab:ResetUndo()
41+
build.itemsTab.modFlag = false
42+
43+
control:OnSelClick(1, result, true)
44+
45+
assert.are.equal(initialItemCount + 1, #build.itemsTab.itemOrderList)
46+
assert.are.equal(0, socketControl.selItemId)
47+
assert.is_true(build.itemsTab.modFlag)
48+
49+
build.itemsTab:Undo()
50+
assert.are.equal(initialItemCount, #build.itemsTab.itemOrderList)
51+
end)
52+
end)

‎src/Classes/TimelessJewelListControl.lua‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ function TimelessJewelListControlClass:AddValueTooltip(tooltip, index, data)
298298
if not self.noTooltip then
299299
if self.list[index].label:match("B2B2B2") == nil then
300300
tooltip:AddLine(16, "^7Double click to add this jewel to your build.")
301+
if self.build.timelessData.socketAllocate then
302+
if socket and self.build.spec.allocNodes[socketId] then
303+
tooltip:AddLine(16, "^7It will be socketed into " .. (data.socketLabel or self.sharedList.socket.label or socketId) .. ".")
304+
else
305+
tooltip:AddLine(16, colorCodes.WARNING .. "That jewel socket is not allocated, so the jewel will only be added to your items.")
306+
end
307+
end
301308
else
302309
tooltip:AddLine(16, "^7" .. self.sharedList.type.label .. " " .. data.seed .. " was successfully added to your build.")
303310
end
@@ -328,8 +335,18 @@ end
328335
function TimelessJewelListControlClass:OnSelClick(index, data, doubleClick)
329336
if doubleClick and self.list[index].label:match("B2B2B2") == nil then
330337
local item = self:GetJewelItem(data)
331-
self.build.itemsTab:AddItem(item, true)
332-
self.build.itemsTab:PopulateSlots()
338+
local itemsTab = self.build.itemsTab
339+
itemsTab:AddItem(item, true)
340+
if self.build.timelessData.socketAllocate then
341+
local socketId = data.socketId or self.sharedList.socket.id
342+
local socketControl = socketId ~= -1 and itemsTab.sockets[socketId]
343+
if socketControl and self.build.spec.allocNodes[socketId] and itemsTab:IsItemValidForSlot(item, socketControl.slotName) then
344+
socketControl:SetSelItemId(item.id)
345+
self.build.buildFlag = true
346+
end
347+
end
348+
itemsTab:PopulateSlots()
349+
itemsTab:AddUndoState()
333350
self.list[index].label = "^xB2B2B2" .. self.list[index].label
334351
end
335352
end

‎src/Classes/TreeTab.lua‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,20 @@ function TreeTabClass:FindTimelessJewel()
16701670
end
16711671
controls.socketFilter.state = timelessData.socketFilter
16721672

1673+
-- own row under the socket filter, so it never collides with the node distance slider
1674+
controls.socketAllocate = new("CheckBoxControl"):CheckBoxControl({"TOPLEFT", controls.socketFilter, "BOTTOMLEFT"}, {0, rowSpacing, rowHeight}, nil, function(value)
1675+
timelessData.socketAllocate = value
1676+
self.build.modFlag = true
1677+
end)
1678+
controls.socketAllocateLabel = new("LabelControl"):LabelControl({"RIGHT", controls.socketAllocate, "LEFT"}, {-labelSpacing, 0, 0, labelHeight}, "^7Socket Jewel:")
1679+
controls.socketAllocate.tooltipFunc = function(tooltip, mode, index, value)
1680+
tooltip:Clear()
1681+
tooltip:AddLine(16, "^7Double clicking a result also equips the jewel in its jewel socket.")
1682+
tooltip:AddLine(16, "^7The socket must be allocated on your current tree; if it isn't, the jewel is only added to your item list.")
1683+
tooltip:AddLine(16, "^7A jewel already in that socket is replaced.")
1684+
end
1685+
controls.socketAllocate.state = timelessData.socketAllocate
1686+
16731687
-- Protect notables that must not be replaced by Militant Faith or Reclaimed Malevolence.
16741688
controls.protectAllocatedLabel = new("LabelControl"):LabelControl({ "TOPLEFT", nil, "TOPLEFT" }, {
16751689
15,
@@ -1750,7 +1764,7 @@ function TreeTabClass:FindTimelessJewel()
17501764
local scrollWheelSpeedTbl2 = { ["SHIFT"] = 0.2, ["CTRL"] = 0.002, ["DEFAULT"] = 0.02 }
17511765

17521766
local nodeSliderStatLabel = "None"
1753-
controls.nodeSlider = new("SliderControl"):SliderControl({"TOPLEFT", controls.socketFilter, "BOTTOMLEFT"}, {0, rowSpacing, 200, rowHeight}, function(value)
1767+
controls.nodeSlider = new("SliderControl"):SliderControl({"TOPLEFT", controls.socketAllocate, "BOTTOMLEFT"}, {0, rowSpacing, 200, rowHeight}, function(value)
17541768
controls.nodeSliderValue.label = s_format("^7%.3f", value * 10)
17551769
parseSearchList(1, controls.searchListFallback and controls.searchListFallback.shown or false)
17561770
end, scrollWheelSpeedTbl)
@@ -2867,6 +2881,8 @@ function TreeTabClass:FindTimelessJewel()
28672881
end
28682882
end)
28692883

2870-
local panelHeight = 565
2884+
-- the settings column is top anchored and the results/trade block bottom anchored,
2885+
-- so the panel grows by a row for every row the settings column gains
2886+
local panelHeight = 565 + rowSpacing + rowHeight
28712887
main:OpenPopup(panelWidth, panelHeight, "Find a Timeless Jewel", controls)
28722888
end

‎src/Modules/Build.lua‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ function buildMode:Load(xml, fileName)
10051005
idx = tonumber(child.attrib.fallbackWeightModeIdx)
10061006
}
10071007
self.timelessData.socketFilter = child.attrib.socketFilter == "true"
1008+
self.timelessData.socketAllocate = child.attrib.socketAllocate == "true"
10081009
self.timelessData.socketFilterDistance = tonumber(child.attrib.socketFilterDistance) or 0
10091010
self.timelessData.searchList = child.attrib.searchList
10101011
self.timelessData.searchListFallback = child.attrib.searchListFallback
@@ -1086,6 +1087,7 @@ function buildMode:Save(xml)
10861087
jewelSocketId = next(self.timelessData.jewelSocket) and tostring(self.timelessData.jewelSocket.id),
10871088
fallbackWeightModeIdx = next(self.timelessData.fallbackWeightMode) and tostring(self.timelessData.fallbackWeightMode.idx),
10881089
socketFilter = self.timelessData.socketFilter and "true",
1090+
socketAllocate = self.timelessData.socketAllocate and "true",
10891091
socketFilterDistance = self.timelessData.socketFilterDistance and tostring(self.timelessData.socketFilterDistance),
10901092
searchList = self.timelessData.searchList and tostring(self.timelessData.searchList),
10911093
searchListFallback = self.timelessData.searchListFallback and tostring(self.timelessData.searchListFallback)

0 commit comments

Comments
 (0)