Skip to content

Commit 0dda872

Browse files
committed
fix: preserve skill substate on reimport
1 parent df0d274 commit 0dda872

2 files changed

Lines changed: 97 additions & 6 deletions

File tree

spec/System/TestImportReimport_spec.lua

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,67 @@ describe("TestImportReimport", function()
33
newBuild()
44
end)
55

6+
local function reimportSingleSocketedGem(itemTypeLine, inventoryId, gemName)
7+
build.importTab.controls.charImportItemsClearSkills.state = true
8+
build.importTab.controls.charImportItemsClearItems.state = false
9+
build.importTab:ImportItemsAndSkills(string.format([=[
10+
{
11+
"character": {
12+
"level": 12
13+
},
14+
"items": [
15+
{
16+
"id": "item-1",
17+
"frameType": 0,
18+
"name": "",
19+
"typeLine": "%s",
20+
"inventoryId": "%s",
21+
"ilvl": 10,
22+
"properties": [],
23+
"sockets": [
24+
{ "group": 0, "sColour": "R" }
25+
],
26+
"socketedItems": [
27+
{
28+
"socket": 0,
29+
"support": false,
30+
"typeLine": "%s",
31+
"properties": [
32+
{ "name": "Level", "values": [["20", 0]] },
33+
{ "name": "Quality", "values": [["+0%%", 0]] }
34+
]
35+
}
36+
]
37+
}
38+
]
39+
}
40+
]=], itemTypeLine, inventoryId, gemName))
41+
runCallback("OnFrame")
42+
end
43+
44+
local function assertReimportPreservesSkillSubstate(slotName, itemTypeLine, inventoryId, gemName, fieldName, fieldValue)
45+
build.skillsTab:PasteSocketGroup(string.format([[
46+
Slot: %s
47+
%s 20/0 Default 1
48+
]], slotName, gemName))
49+
runCallback("OnFrame")
50+
51+
local socketGroup = build.skillsTab.socketGroupList[1]
52+
local srcInstance = socketGroup.displaySkillList[1].activeEffect.srcInstance
53+
srcInstance[fieldName] = fieldValue
54+
srcInstance[fieldName.."Calcs"] = fieldValue
55+
build.modFlag = true
56+
build.buildFlag = true
57+
runCallback("OnFrame")
58+
59+
reimportSingleSocketedGem(itemTypeLine, inventoryId, gemName)
60+
61+
socketGroup = build.skillsTab.socketGroupList[1]
62+
srcInstance = socketGroup.displaySkillList[1].activeEffect.srcInstance
63+
assert.are.equal(fieldValue, srcInstance[fieldName])
64+
assert.are.equal(fieldValue, srcInstance[fieldName.."Calcs"])
65+
end
66+
667
it("preserves full DPS state and manually disabled gems when reimporting items and skills", function()
768
build.skillsTab:PasteSocketGroup([[
869
Slot: Helmet
@@ -80,4 +141,16 @@ Added Fire Damage 1/0 Default DISABLED 1
80141
assert.are.equal(2, socketGroup.gemList[3].level)
81142
assert.is_false(socketGroup.gemList[3].enabled)
82143
end)
144+
145+
it("preserves skill part selection when reimporting items and skills", function()
146+
assertReimportPreservesSkillSubstate("Helmet", "Iron Hat", "Helm", "Blight", "skillPart", 2)
147+
end)
148+
149+
it("preserves stage count when reimporting items and skills", function()
150+
assertReimportPreservesSkillSubstate("Weapon 1", "Driftwood Wand", "Weapon", "Scorching Ray", "skillStageCount", 8)
151+
end)
152+
153+
it("preserves mine count when reimporting items and skills", function()
154+
assertReimportPreservesSkillSubstate("Gloves", "Rawhide Gloves", "Gloves", "Pyroclast Mine", "skillMineCount", 12)
155+
end)
83156
end)

src/Classes/ImportTab.lua

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,17 @@ local function getSocketGroupReimportKey(socketGroup)
746746
end
747747

748748
local function snapshotSocketGroupReimportState(socketGroup, isMainGroup)
749-
local gemEnabledStates = { }
749+
local gemStates = { }
750750
for gemIndex, gem in ipairs(socketGroup.gemList) do
751-
gemEnabledStates[gemIndex] = gem.enabled
751+
gemStates[gemIndex] = {
752+
enabled = gem.enabled,
753+
skillPart = gem.skillPart,
754+
skillPartCalcs = gem.skillPartCalcs,
755+
skillStageCount = gem.skillStageCount,
756+
skillStageCountCalcs = gem.skillStageCountCalcs,
757+
skillMineCount = gem.skillMineCount,
758+
skillMineCountCalcs = gem.skillMineCountCalcs,
759+
}
752760
end
753761
return {
754762
enabled = socketGroup.enabled,
@@ -757,22 +765,32 @@ local function snapshotSocketGroupReimportState(socketGroup, isMainGroup)
757765
label = socketGroup.label,
758766
mainActiveSkill = socketGroup.mainActiveSkill,
759767
mainActiveSkillCalcs = socketGroup.mainActiveSkillCalcs,
760-
gemEnabledStates = gemEnabledStates,
768+
gemStates = gemStates,
761769
isMainGroup = isMainGroup,
762770
}
763771
end
764772

773+
local function applyGemReimportState(gem, state)
774+
gem.enabled = state.enabled
775+
gem.skillPart = state.skillPart
776+
gem.skillPartCalcs = state.skillPartCalcs
777+
gem.skillStageCount = state.skillStageCount
778+
gem.skillStageCountCalcs = state.skillStageCountCalcs
779+
gem.skillMineCount = state.skillMineCount
780+
gem.skillMineCountCalcs = state.skillMineCountCalcs
781+
end
782+
765783
local function applySocketGroupReimportState(socketGroup, state)
766784
socketGroup.enabled = state.enabled
767785
socketGroup.includeInFullDPS = state.includeInFullDPS
768786
socketGroup.groupCount = state.groupCount
769787
socketGroup.label = state.label
770788
socketGroup.mainActiveSkill = state.mainActiveSkill
771789
socketGroup.mainActiveSkillCalcs = state.mainActiveSkillCalcs
772-
if state.gemEnabledStates then
773-
for gemIndex, enabled in ipairs(state.gemEnabledStates) do
790+
if state.gemStates then
791+
for gemIndex, gemState in ipairs(state.gemStates) do
774792
if socketGroup.gemList[gemIndex] then
775-
socketGroup.gemList[gemIndex].enabled = enabled
793+
applyGemReimportState(socketGroup.gemList[gemIndex], gemState)
776794
end
777795
end
778796
end

0 commit comments

Comments
 (0)