Skip to content

Commit f629d8d

Browse files
Wires77pHiney
andauthored
Add league information to save xmls for imported characters (#9760)
Co-authored-by: Hiney <pHiney@users.noreply.github.com>
1 parent f717d7d commit f629d8d

1 file changed

Lines changed: 52 additions & 5 deletions

File tree

src/Classes/ImportTab.lua

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ local ImportTabClass = newClass("ImportTab", "ControlHost", "Control", function(
3737
self.controls.accountNameHeader.shown = function()
3838
return self.charImportMode == "GETACCOUNTNAME"
3939
end
40-
self.controls.accountRealm = new("DropDownControl", {"TOPLEFT",self.controls.accountNameHeader,"BOTTOMLEFT"}, {0, 4, 60, 20}, realmList )
41-
self.controls.accountRealm:SelByValue( main.lastRealm or "PC", "id" )
40+
self.controls.accountRealm = new("DropDownControl", {"TOPLEFT",self.controls.accountNameHeader,"BOTTOMLEFT"}, {0, 4, 60, 20}, realmList)
41+
self.controls.accountRealm:SelByValue(main.lastRealm or "PC", "id")
4242
self.controls.accountName = new("EditControl", {"LEFT",self.controls.accountRealm,"RIGHT"}, {8, 0, 200, 20}, main.lastAccountName or "", nil, "%c", nil, nil, nil, nil, true)
4343
self.controls.accountName.pasteFilter = function(text)
4444
return text:gsub(".", function(c)
@@ -369,7 +369,9 @@ end)
369369

370370
function ImportTabClass:Load(xml, fileName)
371371
self.lastRealm = xml.attrib.lastRealm
372-
self.controls.accountRealm:SelByValue( self.lastRealm or main.lastRealm or "PC", "id" )
372+
self.controls.accountRealm:SelByValue(self.lastRealm or main.lastRealm or "PC", "id")
373+
self.lastLeague = xml.attrib.lastLeague
374+
self.controls.charSelectLeague:SelByValue(self.lastLeague or "Standard", "id")
373375
self.lastAccountHash = xml.attrib.lastAccountHash
374376
self.importLink = xml.attrib.importLink
375377
self.controls.enablePartyExportBuffs.state = xml.attrib.exportParty == "true"
@@ -387,6 +389,7 @@ end
387389
function ImportTabClass:Save(xml)
388390
xml.attrib = {
389391
lastRealm = self.lastRealm,
392+
lastLeague = self.lastLeague,
390393
lastAccountHash = self.lastAccountHash,
391394
lastCharacterHash = self.lastCharacterHash,
392395
exportParty = tostring(self.controls.enablePartyExportBuffs.state),
@@ -414,6 +417,23 @@ function ImportTabClass:Draw(viewPort, inputEvents)
414417
end
415418

416419
function ImportTabClass:DownloadCharacterList()
420+
function FindMatchingStandardLeague(league)
421+
-- Find a Standard league name for a given league name
422+
-- Reference https://api.pathofexile.com/league?realm=pc
423+
if string.find(league, "Hardcore") then
424+
return "Hardcore"
425+
elseif string.find(league, "HC SSF") then
426+
-- includes Ruthless "HC SSF R "
427+
return "SSF Hardcore"
428+
elseif string.find(league, "SSF") then
429+
-- Any non HardCore SSF's - includes Ruthless "SSF R "
430+
return "SSF Standard"
431+
else
432+
-- normal league and ruthless league (Sanctum, Ruthless Sanctum)
433+
return "Standard"
434+
end
435+
end
436+
417437
self.charImportMode = "DOWNLOADCHARLIST"
418438
self.charImportStatus = "Retrieving character list..."
419439
local realm = realmList[self.controls.accountRealm.selIndex]
@@ -488,6 +508,7 @@ function ImportTabClass:DownloadCharacterList()
488508
end
489509
end
490510
table.sort(leagueList)
511+
charSelectLeague = self.controls.charSelectLeague
491512
wipeTable(self.controls.charSelectLeague.list)
492513
for _, league in ipairs(leagueList) do
493514
t_insert(self.controls.charSelectLeague.list, {
@@ -498,8 +519,25 @@ function ImportTabClass:DownloadCharacterList()
498519
t_insert(self.controls.charSelectLeague.list, {
499520
label = "All",
500521
})
501-
if self.controls.charSelectLeague.selIndex > #self.controls.charSelectLeague.list then
502-
self.controls.charSelectLeague.selIndex = 1
522+
-- set the league combo to the last used if possible, used for previously imported characters
523+
if self.lastLeague then
524+
charSelectLeague:SelByValue(self.lastLeague, "league")
525+
-- check that it worked
526+
if charSelectLeague:GetSelValueByKey("league") ~= self.lastLeague then
527+
-- League maybe over, Character will be in standard
528+
standardLeagueName = FindMatchingStandardLeague(self.lastLeague)
529+
self.controls.charSelectLeague:SelByValue(standardLeagueName, "league")
530+
if charSelectLeague:GetSelValueByKey("league") ~= standardLeagueName then
531+
-- give up and select the first entry. Ruthless mode may not have Standard equivalents
532+
charSelectLeague.selIndex = 1
533+
else
534+
self.lastLeague = standardLeagueName
535+
end
536+
end
537+
else
538+
if self.controls.charSelectLeague.selIndex > #self.controls.charSelectLeague.list then
539+
self.controls.charSelectLeague.selIndex = 1
540+
end
503541
end
504542
self.lastCharList = charList
505543
self:BuildCharacterList(self.controls.charSelectLeague:GetSelValueByKey("league"))
@@ -606,6 +644,9 @@ function ImportTabClass:DownloadPassiveTree()
606644
return
607645
end
608646
self.lastCharacterHash = common.sha1(charData.name)
647+
if not self.lastLeague then
648+
self.lastLeague = charSelectLeague:GetSelValueByKey("league")
649+
end
609650
self:ImportPassiveTreeAndJewels(response.body, charData)
610651
end, sessionID and { header = "Cookie: POESESSID=" .. sessionID })
611652
end
@@ -628,6 +669,9 @@ function ImportTabClass:DownloadItems()
628669
return
629670
end
630671
self.lastCharacterHash = common.sha1(charData.name)
672+
if not self.lastLeague then
673+
self.lastLeague = charSelectLeague:GetSelValueByKey("league")
674+
end
631675
self:ImportItemsAndSkills(response.body)
632676
end, sessionID and { header = "Cookie: POESESSID=" .. sessionID })
633677
end
@@ -711,6 +755,9 @@ function ImportTabClass:ImportPassiveTreeAndJewels(json, charData)
711755
self.build.treeTab:SetActiveSpec(self.build.treeTab.activeSpec)
712756
self.build.spec:BuildClusterJewelGraphs()
713757
self.build.spec:AddUndoState()
758+
if not self.lastLeague then
759+
self.lastLeague = charSelectLeague:GetSelValueByKey("league")
760+
end
714761
self.build.characterLevel = charData.level
715762
self.build.characterLevelAutoMode = false
716763
self.build.configTab:UpdateLevel()

0 commit comments

Comments
 (0)