Skip to content

Commit 0a0a9fb

Browse files
committed
Handle unique names and prefix in import loadouts
Signed-off-by: Tomas Slusny <[email protected]>
1 parent c60affd commit 0a0a9fb

File tree

7 files changed

+63
-34
lines changed

7 files changed

+63
-34
lines changed

src/Classes/ConfigTab.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont
611611
self.controls.scrollBar = new("ScrollBarControl", {"TOPRIGHT",self,"TOPRIGHT"}, {0, 0, 18, 0}, 50, "VERTICAL", true)
612612
end)
613613

614-
function ConfigTabClass:Load(xml, fileName, appendConfigs, prefix)
614+
function ConfigTabClass:Load(xml, fileName, appendConfigs)
615615
if not appendConfigs then
616616
self.activeConfigSetId = 0
617617
self.configSets = { }
@@ -669,12 +669,7 @@ function ConfigTabClass:Load(xml, fileName, appendConfigs, prefix)
669669
end
670670
setInputAndPlaceholder(node, 1)
671671
else
672-
local configSetId = tonumber(node.attrib.id)
673-
local title = node.attrib.title or "Default"
674-
if appendConfigs and prefix then
675-
title = prefix .. title
676-
end
677-
local configSet = self:NewConfigSet(not appendConfigs and configSetId, title)
672+
local configSet = self:NewConfigSet(not appendConfigs and tonumber(node.attrib.id) or nil, node.attrib.title or "Default")
678673
t_insert(self.configSetOrderList, configSet.id)
679674
for _, child in ipairs(node) do
680675
setInputAndPlaceholder(child, configSet.id)

src/Classes/ImportTab.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,15 @@ You can get this from your web browser's cookies while logged into the Path of E
318318
local controls = { }
319319
t_insert(controls, new("LabelControl", nil, {0, 20, 0, 16}, colorCodes.WARNING.."Warning:^7 Importing many loadouts into the same build"))
320320
t_insert(controls, new("LabelControl", nil, {0, 36, 0, 16}, "may cause performance issues. Use with caution."))
321-
t_insert(controls, new("LabelControl", nil, {0, 64, 0, 16}, "^7Prefix for imported loadouts (optional):"))
322-
controls.prefix = new("EditControl", nil, {0, 84, 350, 20}, "", nil, nil, 50)
321+
t_insert(controls, new("LabelControl", nil, {0, 64, 0, 16}, "^7Prefix for imported loadouts:"))
322+
controls.prefix = new("EditControl", nil, {0, 84, 350, 20}, "Imported - ", nil, nil, 50)
323323
controls.import = new("ButtonControl", nil, {-45, 114, 80, 20}, "Import", function()
324324
local prefix = controls.prefix.buf
325+
if prefix == "" then
326+
prefix = "Imported - "
327+
end
325328
main:ClosePopup()
326-
self.build:ImportLoadouts(self.importCodeXML, prefix ~= "" and prefix or nil)
329+
self.build:ImportLoadouts(self.importCodeXML, prefix)
327330
end)
328331
t_insert(controls, new("ButtonControl", nil, {45, 114, 80, 20}, "Cancel", function()
329332
main:ClosePopup()

src/Classes/ItemsTab.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ holding Shift will put it in the second.]])
958958
self.lastSlot = self.slots[baseSlots[#baseSlots]]
959959
end)
960960

961-
function ItemsTabClass:Load(xml, dbFileName, appendItems, prefix)
961+
function ItemsTabClass:Load(xml, dbFileName, appendItems)
962962
if not appendItems then
963963
self.activeItemSetId = 0
964964
self.itemSets = { }
@@ -1037,11 +1037,7 @@ function ItemsTabClass:Load(xml, dbFileName, appendItems, prefix)
10371037
end
10381038
elseif node.elem == "ItemSet" then
10391039
local itemSet = self:NewItemSet(not appendItems and tonumber(node.attrib.id) or nil)
1040-
local title = node.attrib.title
1041-
if appendItems and prefix then
1042-
title = prefix .. (title or "")
1043-
end
1044-
itemSet.title = title
1040+
itemSet.title = node.attrib.title
10451041
itemSet.useSecondWeaponSet = node.attrib.useSecondWeaponSet == "true"
10461042
for _, child in ipairs(node) do
10471043
if child.elem == "Slot" then

src/Classes/PassiveSpec.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,8 @@ function PassiveSpecClass:Init(treeVersion, convert)
8383
self.hashOverrides = { }
8484
end
8585

86-
function PassiveSpecClass:Load(xml, dbFileName, prefix)
87-
local title = xml.attrib.title
88-
if prefix then
89-
title = prefix .. (title or "")
90-
end
91-
self.title = title
86+
function PassiveSpecClass:Load(xml, dbFileName)
87+
self.title = xml.attrib.title
9288
local url
9389
for _, node in pairs(xml) do
9490
if type(node) == "table" then

src/Classes/SkillsTab.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ function SkillsTabClass:LoadSkill(node, skillSetId)
374374
t_insert(self.skillSets[skillSetId].socketGroupList, socketGroup)
375375
end
376376

377-
function SkillsTabClass:Load(xml, fileName, appendSkills, prefix)
377+
function SkillsTabClass:Load(xml, fileName, appendSkills)
378378
if not appendSkills then
379379
self.activeSkillSetId = 0
380380
self.skillSets = { }
@@ -416,11 +416,7 @@ function SkillsTabClass:Load(xml, fileName, appendSkills, prefix)
416416

417417
if node.elem == "SkillSet" then
418418
local skillSet = self:NewSkillSet(not appendSkills and tonumber(node.attrib.id) or nil)
419-
local title = node.attrib.title
420-
if appendSkills and prefix then
421-
title = prefix .. (title or "")
422-
end
423-
skillSet.title = title
419+
skillSet.title = node.attrib.title
424420
t_insert(self.skillSetOrderList, skillSet.id)
425421
for _, subNode in ipairs(node) do
426422
self:LoadSkill(subNode, skillSet.id)

src/Classes/TreeTab.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ function TreeTabClass:GetSpecList()
444444
return newSpecList
445445
end
446446

447-
function TreeTabClass:Load(xml, dbFileName, appendSpecs, prefix, itemIdMap)
447+
function TreeTabClass:Load(xml, dbFileName, appendSpecs, itemIdMap)
448448
if not appendSpecs then
449449
self.specList = { }
450450
end
@@ -482,7 +482,7 @@ function TreeTabClass:Load(xml, dbFileName, appendSpecs, prefix, itemIdMap)
482482
end
483483

484484
local newSpec = new("PassiveSpec", self.build, node.attrib.treeVersion or defaultTreeVersion)
485-
newSpec:Load(node, dbFileName, prefix)
485+
newSpec:Load(node, dbFileName)
486486
t_insert(self.specList, newSpec)
487487
end
488488
end

src/Modules/Build.lua

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,45 @@ function buildMode:ImportLoadouts(xmlText, prefix)
18881888
return true
18891889
end
18901890

1891+
-- Ensure unique names for imported entries
1892+
local usedNames = {}
1893+
local function makeUniqueName(name)
1894+
local baseName = name
1895+
local suffix = 2
1896+
while usedNames[name] do
1897+
name = baseName .. " (" .. suffix .. ")"
1898+
suffix = suffix + 1
1899+
end
1900+
usedNames[name] = true
1901+
return name
1902+
end
1903+
local function markName(name)
1904+
usedNames[name or "Default"] = true
1905+
end
1906+
1907+
-- Collect existing names from current build
1908+
for _, itemSet in pairs(self.itemsTab.itemSets) do
1909+
markName(itemSet.title)
1910+
end
1911+
for _, skillSet in pairs(self.skillsTab.skillSets) do
1912+
markName(skillSet.title)
1913+
end
1914+
for _, spec in ipairs(self.treeTab.specList) do
1915+
markName(spec.title)
1916+
end
1917+
for _, configSet in pairs(self.configTab.configSets) do
1918+
markName(configSet.title)
1919+
end
1920+
1921+
-- Pre-process the XML to add prefix and ensure unique names
1922+
local function addPrefixAndMakeUnique(node)
1923+
local titleAttr = "title"
1924+
if node.attrib and node.attrib[titleAttr] then
1925+
local title = prefix .. (node.attrib[titleAttr] or "")
1926+
node.attrib[titleAttr] = makeUniqueName(title)
1927+
end
1928+
end
1929+
18911930
-- Extract relevant sections from imported XML
18921931
local itemsSection = nil
18931932
local skillsSection = nil
@@ -1904,27 +1943,31 @@ function buildMode:ImportLoadouts(xmlText, prefix)
19041943
itemsSection = node
19051944
for _, n in ipairs(itemsSection) do
19061945
if n.elem == "ItemSet" then
1946+
addPrefixAndMakeUnique(n)
19071947
itemSetCount = itemSetCount + 1
19081948
end
19091949
end
19101950
elseif node.elem == "Skills" then
19111951
skillsSection = node
19121952
for _, n in ipairs(skillsSection) do
19131953
if n.elem == "SkillSet" then
1954+
addPrefixAndMakeUnique(n)
19141955
skillSetCount = skillSetCount + 1
19151956
end
19161957
end
19171958
elseif node.elem == "Tree" then
19181959
treeSection = node
19191960
for _, n in ipairs(treeSection) do
19201961
if n.elem == "Spec" then
1962+
addPrefixAndMakeUnique(n)
19211963
treeSpecCount = treeSpecCount + 1
19221964
end
19231965
end
19241966
elseif node.elem == "Config" then
19251967
configSection = node
19261968
for _, n in ipairs(configSection) do
19271969
if n.elem == "ConfigSet" then
1970+
addPrefixAndMakeUnique(n)
19281971
configSetCount = configSetCount + 1
19291972
end
19301973
end
@@ -1939,17 +1982,17 @@ function buildMode:ImportLoadouts(xmlText, prefix)
19391982

19401983
local itemIdMap = { }
19411984
if itemsSection then
1942-
itemIdMap = self.itemsTab:Load(itemsSection, self.dbFileName, true, prefix) or { }
1985+
itemIdMap = self.itemsTab:Load(itemsSection, self.dbFileName, true) or { }
19431986
end
19441987
if skillsSection then
1945-
self.skillsTab:Load(skillsSection, self.dbFileName, true, prefix)
1988+
self.skillsTab:Load(skillsSection, self.dbFileName, true)
19461989
end
19471990
if treeSection then
1948-
self.treeTab:Load(treeSection, self.dbFileName, true, prefix, itemIdMap)
1991+
self.treeTab:Load(treeSection, self.dbFileName, true, nil, itemIdMap)
19491992
self.treeTab:PostLoad()
19501993
end
19511994
if configSection then
1952-
self.configTab:Load(configSection, self.dbFileName, true, prefix)
1995+
self.configTab:Load(configSection, self.dbFileName, true)
19531996
end
19541997

19551998
-- Mark build as modified

0 commit comments

Comments
 (0)