@@ -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