Skip to content

Commit 4a8ae06

Browse files
committed
bug fix for test case copy -> copy -> rename/delete
clean up old comments, remove unused variables refactor loops so we only do it once and set id, index as needed
1 parent c9b5563 commit 4a8ae06

2 files changed

Lines changed: 44 additions & 112 deletions

File tree

src/Classes/ItemSetListControl.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ end
122122

123123
function ItemSetListClass:OnSelDelete(index, itemSetId)
124124
local itemSet = self.itemsTab.itemSets[itemSetId]
125-
--ConPrintf("OnSelDelete, itemSet = "..itemSet.title or "Default"..", index = "..index..", itemSetId = "..itemSetId)
126125
if #self.list > 1 then
127126
main:OpenConfirmPopup("Delete Item Set", "Are you sure you want to delete '"..(itemSet.title or "Default").."'?\nThis will not delete any items used by the set.", "Delete", function()
128127
t_remove(self.list, index)
@@ -141,7 +140,6 @@ end
141140
-- bypass confirmation popup, used by Loadouts
142141
function ItemSetListClass:DeleteById(index, itemSetId, sync)
143142
local itemSet = self.itemsTab.itemSets[itemSetId]
144-
--ConPrintf("DeleteById, itemSet = "..itemSet.title or "Default"..", index = "..index..", itemSetId = "..itemSetId)
145143
if #self.list > 1 then
146144
t_remove(self.list, index)
147145
self.itemsTab.itemSets[itemSetId] = nil

src/Modules/Build.lua

Lines changed: 44 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -332,72 +332,59 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild, importLin
332332
local selectedLoadoutTitle = existingLoadoutsList[1] or "Default"
333333
-- set indices of each type for selected loadout for copy/delete/rename
334334
local selectedLoadoutTreeId = { }
335-
local selectedLoadoutItemId = { }
336-
local selectedLoadoutSkillId = { }
337-
local selectedLoadoutConfigId = { }
335+
local selectedLoadoutItemId, selectedLoadoutItemIndex = { }, { } -- index needed for delete loadout
336+
local selectedLoadoutSkillId, selectedLoadoutSkillIndex = { }, { }
337+
local selectedLoadoutConfigId, selectedLoadoutConfigIndex = { }, { }
338338
local loadoutTitleOrIdentifier = ""
339339
-- ***
340340

341-
local function renameSets(title, newFromExisting)
342-
if newFromExisting then
343-
self.treeTab.specList[self.treeTab.activeSpec].title = title
344-
self.itemsTab.itemSets[self.itemsTab.activeItemSetId].title = title
345-
self.skillsTab.skillSets[self.skillsTab.activeSkillSetId].title = title
346-
self.configTab.configSets[self.configTab.activeConfigSetId].title = title
347-
else
348-
self.treeTab.specList[selectedLoadoutTreeId].title = title
349-
--self.itemsTab.itemSets[selectedLoadoutItemId].title = title
350-
for _, id in pairs(self.itemsTab.itemSetOrderList) do
351-
if (string.match(self.itemsTab.itemSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.itemsTab.itemSets[id].title or "Default" == loadoutTitleOrIdentifier) then
352-
self.itemsTab.itemSets[id].title = title
353-
break
354-
end
355-
end
356-
--self.skillsTab.skillSets[selectedLoadoutSkillId].title = title
357-
for _, id in pairs(self.skillsTab.skillSetOrderList) do
358-
if (string.match(self.skillsTab.skillSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.skillsTab.skillSets[id].title or "Default" == loadoutTitleOrIdentifier) then
359-
self.skillsTab.skillSets[id].title = title
360-
break
361-
end
362-
end
363-
--self.configTab.configSets[selectedLoadoutConfigId].title = title
364-
for _, id in pairs(self.configTab.configSetOrderList) do
365-
if (string.match(self.configTab.configSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.configTab.configSets[id].title or "Default" == loadoutTitleOrIdentifier) then
366-
self.configTab.configSets[id].title = title
367-
break
368-
end
369-
end
370-
end
371-
end
372341
local function setSelectedLoadout(title)
373342
selectedLoadoutTreeId, loadoutTitleOrIdentifier = findNamedSetId(self.treeTab:GetSpecList(), title, self.treeListSpecialLinks)
374-
375343
-- because we are creating the SetListControl in real time, the SetOrderLists can get out of sync with the ItemSets, SkillSets, ConfigSets
376344
-- so we will loop until we find the title or identifier match from the selected loadout
377-
--selectedLoadoutItemId = findSetId(self.itemsTab.itemSetOrderList, title, self.itemsTab.itemSets, self.itemListSpecialLinks)
378-
for _, id in pairs(self.itemsTab.itemSetOrderList) do
379-
if (string.match(self.itemsTab.itemSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.itemsTab.itemSets[id].title or "Default" == loadoutTitleOrIdentifier) then
345+
for index, id in pairs(self.itemsTab.itemSetOrderList) do
346+
if (string.match(self.itemsTab.itemSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or ((self.itemsTab.itemSets[id].title or "Default") == loadoutTitleOrIdentifier) then
380347
selectedLoadoutItemId = id
348+
selectedLoadoutItemIndex = index
381349
break
382350
end
383351
end
384-
--selectedLoadoutSkillId = findSetId(self.skillsTab.skillSetOrderList, title, self.skillsTab.skillSets, self.skillListSpecialLinks)
385-
for _, id in pairs(self.skillsTab.skillSetOrderList) do
386-
if (string.match(self.skillsTab.skillSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.skillsTab.skillSets[id].title or "Default" == loadoutTitleOrIdentifier) then
352+
for index, id in pairs(self.skillsTab.skillSetOrderList) do
353+
if (string.match(self.skillsTab.skillSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or ((self.skillsTab.skillSets[id].title or "Default") == loadoutTitleOrIdentifier) then
387354
selectedLoadoutSkillId = id
355+
selectedLoadoutSkillIndex = index
388356
break
389357
end
390358
end
391-
--selectedLoadoutConfigId = findSetId(self.configTab.configSetOrderList, title, self.configTab.configSets, self.configListSpecialLinks)
392-
for _, id in pairs(self.configTab.configSetOrderList) do
393-
if (string.match(self.configTab.configSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.configTab.configSets[id].title or "Default" == loadoutTitleOrIdentifier) then
359+
for index, id in pairs(self.configTab.configSetOrderList) do
360+
if (string.match(self.configTab.configSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or ((self.configTab.configSets[id].title or "Default") == loadoutTitleOrIdentifier) then
394361
selectedLoadoutConfigId = id
362+
selectedLoadoutConfigIndex = index
395363
break
396364
end
397365
end
398366
end
399367
setSelectedLoadout(selectedLoadoutTitle)
400368

369+
local function copyLoadout(loadoutTitle)
370+
local oldSpec = self.treeTab.specList[selectedLoadoutTreeId]
371+
local newSpec = passiveSpecListControl.controls.copy.onClick(oldSpec)
372+
t_insert(self.treeTab.specList, newSpec)
373+
newSpec.title = loadoutTitle
374+
375+
local newItemSet = itemSetListControl.controls.copy.onClick(selectedLoadoutItemId)
376+
t_insert(self.itemsTab.itemSetOrderList, newItemSet.id)
377+
newItemSet.title = loadoutTitle
378+
379+
local newSkillSet = skillSetListControl.controls.copy.onClick(selectedLoadoutSkillId)
380+
t_insert(self.skillsTab.skillSetOrderList, newSkillSet.id)
381+
newSkillSet.title = loadoutTitle
382+
383+
local newConfigSet = configSetListControl.controls.copy.onClick(selectedLoadoutConfigId)
384+
t_insert(self.configTab.configSetOrderList, newConfigSet.id)
385+
newConfigSet.title = loadoutTitle
386+
end
387+
401388
if value == "^7^7Loadouts:" or value == "^7^7-----" then
402389
self.controls.buildLoadouts:SetSel(1)
403390
return
@@ -423,9 +410,9 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild, importLin
423410
end, "If unchecked, a loadout of empty sets will be created.")
424411
controls.save = new("ButtonControl", nil, {-45, 100, 80, 20}, "Create", function()
425412
local loadoutTitle = controls.loadoutName.buf
426-
-- if we're making a loadout out of the existing sets we only need to rename them to match
413+
-- make a copy so we don't break any existing loadouts if any of their sets are currently active
427414
if createFromExistingSets then
428-
renameSets(loadoutTitle, true)
415+
copyLoadout(loadoutTitle)
429416
else
430417
local newSpec = new("PassiveSpec", self, latestTreeVersion)
431418
t_insert(self.treeTab.specList, newSpec)
@@ -467,7 +454,12 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild, importLin
467454
end)
468455

469456
controls.rename = new("ButtonControl", nil, {-45, 125, 80, 20}, "Rename", function()
470-
renameSets(controls.loadoutName.buf)
457+
local title = controls.loadoutName.buf
458+
self.treeTab.specList[selectedLoadoutTreeId].title = title
459+
self.itemsTab.itemSets[selectedLoadoutItemId].title = title
460+
self.skillsTab.skillSets[selectedLoadoutSkillId].title = title
461+
self.configTab.configSets[selectedLoadoutConfigId].title = title
462+
471463
self:SyncLoadouts()
472464
self.modFlag = true
473465
main:ClosePopup()
@@ -494,46 +486,7 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild, importLin
494486
end)
495487

496488
controls.copy = new("ButtonControl", nil, {-45, 125, 80, 20}, "Copy", function()
497-
local loadoutTitle = controls.loadoutName.buf
498-
499-
local oldSpec = self.treeTab.specList[selectedLoadoutTreeId]
500-
local newSpec = passiveSpecListControl.controls.copy.onClick(oldSpec)
501-
t_insert(self.treeTab.specList, newSpec)
502-
newSpec.title = loadoutTitle
503-
504-
--local newItemSet = itemSetListControl.controls.copy.onClick(selectedLoadoutItemId)
505-
local newItemSet
506-
for _, id in pairs(self.itemsTab.itemSetOrderList) do
507-
if (string.match(self.itemsTab.itemSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.itemsTab.itemSets[id].title or "Default" == loadoutTitleOrIdentifier) then
508-
newItemSet = itemSetListControl.controls.copy.onClick(id)
509-
break
510-
end
511-
end
512-
t_insert(self.itemsTab.itemSetOrderList, newItemSet.id)
513-
newItemSet.title = loadoutTitle
514-
515-
--local newSkillSet = skillSetListControl.controls.copy.onClick(selectedLoadoutSkillId)
516-
local newSkillSet
517-
for _, id in pairs(self.skillsTab.skillSetOrderList) do
518-
if (string.match(self.skillsTab.skillSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.skillsTab.skillSets[id].title or "Default" == loadoutTitleOrIdentifier) then
519-
newSkillSet = skillSetListControl.controls.copy.onClick(id)
520-
break
521-
end
522-
end
523-
t_insert(self.skillsTab.skillSetOrderList, newSkillSet.id)
524-
newSkillSet.title = loadoutTitle
525-
526-
--local newConfigSet = configSetListControl.controls.copy.onClick(selectedLoadoutConfigId)
527-
local newConfigSet
528-
for _, id in pairs(self.configTab.configSetOrderList) do
529-
if (string.match(self.configTab.configSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.configTab.configSets[id].title or "Default" == loadoutTitleOrIdentifier) then
530-
newConfigSet = configSetListControl.controls.copy.onClick(id)
531-
break
532-
end
533-
end
534-
t_insert(self.configTab.configSetOrderList, newConfigSet.id)
535-
newConfigSet.title = loadoutTitle
536-
489+
copyLoadout(controls.loadoutName.buf)
537490
self:SyncLoadouts()
538491
self.modFlag = true
539492
main:ClosePopup()
@@ -556,29 +509,10 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild, importLin
556509
controls.delete = new("ButtonControl", nil, {-45, 85, 80, 20}, "Delete", function()
557510
main:OpenConfirmPopup("Delete All", "Are you sure you want to delete this loadout?", "Delete", function()
558511
passiveSpecListControl:DeleteByIndex(selectedLoadoutTreeId)
559-
-- because we are creating the SetListControl in real time, the SetOrderLists can get out of sync with the ItemSets, SkillSets, ConfigSets
560-
-- so we will loop until we find the title or identifier match from the selected loadout
561-
--itemSetListControl:DeleteById(selectedLoadoutItemId)
562-
for index, id in pairs(self.itemsTab.itemSetOrderList) do
563-
if (string.match(self.itemsTab.itemSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.itemsTab.itemSets[id].title or "Default" == loadoutTitleOrIdentifier) then
564-
itemSetListControl:DeleteById(index, id)
565-
break
566-
end
567-
end
568-
--skillSetListControl:DeleteById(selectedLoadoutSkillId)
569-
for index, id in pairs(self.skillsTab.skillSetOrderList) do
570-
if (string.match(self.skillsTab.skillSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.skillsTab.skillSets[id].title or "Default" == loadoutTitleOrIdentifier) then
571-
skillSetListControl:DeleteById(index, id)
572-
break
573-
end
574-
end
575-
--configSetListControl:DeleteById(selectedLoadoutConfigId)
576-
for index, id in pairs(self.configTab.configSetOrderList) do
577-
if (string.match(self.configTab.configSets[id].title or "Default", "%b{}") == loadoutTitleOrIdentifier) or (self.configTab.configSets[id].title or "Default" == loadoutTitleOrIdentifier) then
578-
configSetListControl:DeleteById(index, id)
579-
break
580-
end
581-
end
512+
itemSetListControl:DeleteById(selectedLoadoutItemIndex, selectedLoadoutItemId)
513+
skillSetListControl:DeleteById(selectedLoadoutSkillIndex, selectedLoadoutSkillId)
514+
configSetListControl:DeleteById(selectedLoadoutConfigIndex, selectedLoadoutConfigId)
515+
582516
self:SyncLoadouts()
583517
self.modFlag = true
584518
main:ClosePopup()

0 commit comments

Comments
 (0)