Skip to content

Commit a243930

Browse files
committed
[ISSUE-9451] Loadout Management
* Updated ReorderLoadout callback method to have less nested branching by using more arithmetic comparison
1 parent 2b373f4 commit a243930

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/Modules/Build.lua

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,29 +1012,19 @@ function buildMode:ReorderLoadout(oldIndex, newIndex)
10121012

10131013
self.modFlag = true
10141014

1015-
if oldIndex < newIndex then
1016-
if oldIndex > self.treeTab.activeSpec or newIndex < self.treeTab.activeSpec then
1017-
return
1018-
end
1015+
local activeLoadout = self.treeTab.activeSpec
10191016

1020-
if oldIndex == self.treeTab.activeSpec then
1021-
self:SetActiveLoadout(self:GetLoadoutByName(self.treeTab.specList[newIndex].title or "Default"))
1022-
elseif newIndex >= self.treeTab.activeSpec then
1023-
self:SetActiveLoadout(self:GetLoadoutByName(self.treeTab.specList[self.treeTab.activeSpec - 1].title or
1024-
"Default"))
1025-
end
1026-
else
1027-
if oldIndex < self.treeTab.activeSpec or newIndex > self.treeTab.activeSpec then
1028-
return
1029-
end
1017+
local minVal = m_min(oldIndex, newIndex)
1018+
local maxVal = m_max(oldIndex, newIndex)
1019+
if activeLoadout < minVal or activeLoadout > maxVal then return end
10301020

1031-
if oldIndex == self.treeTab.activeSpec then
1032-
self:SetActiveLoadout(self:GetLoadoutByName(self.treeTab.specList[newIndex].title or "Default"))
1033-
elseif newIndex <= self.treeTab.activeSpec then
1034-
self:SetActiveLoadout(self:GetLoadoutByName(self.treeTab.specList[self.treeTab.activeSpec + 1].title or
1035-
"Default"))
1036-
end
1021+
if oldIndex == activeLoadout then
1022+
activeLoadout = newIndex
1023+
elseif minVal <= activeLoadout and activeLoadout < maxVal then
1024+
activeLoadout = activeLoadout + (oldIndex > newIndex and 1 or -1)
10371025
end
1026+
1027+
self:SetActiveLoadout(self:GetLoadoutByName(self.treeTab.specList[activeLoadout].title or "Default"))
10381028
end
10391029

10401030
function buildMode:EstimatePlayerProgress()

0 commit comments

Comments
 (0)