Skip to content

Commit 2b373f4

Browse files
committed
[ISSUE-9451] Loadout Management
* Moved implementation of ReorderLoadout to buildMode to maintain consistency * Added tests covering the branches in ReorderLoadout
1 parent 423e503 commit 2b373f4

File tree

3 files changed

+184
-25
lines changed

3 files changed

+184
-25
lines changed

spec/System/TestLoadouts_spec.lua

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local t_insert = table.insert
2+
local t_remove = table.remove
23

34
describe("TestLoadouts", function()
45
before_each(function()
@@ -195,6 +196,156 @@ describe("TestLoadouts", function()
195196
assert.is_true(build.modFlag)
196197
end)
197198
end)
199+
200+
describe("ReorderLoadout", function()
201+
local function assertActiveLoadoutByName(expectedName)
202+
local activeSpec = build.treeTab.specList[build.treeTab.activeSpec]
203+
local activeItemSet = build.itemsTab.itemSets[build.itemsTab.activeItemSetId]
204+
local activeSkillSet = build.skillsTab.skillSets[build.skillsTab.activeSkillSetId]
205+
local activeConfigSet = build.configTab.configSets[build.configTab.activeConfigSetId]
206+
assert.is_not_nil(activeSpec)
207+
assert.is_same(expectedName, activeSpec.title)
208+
assert.is_not_nil(activeItemSet)
209+
assert.is_same(expectedName, activeItemSet.title)
210+
assert.is_not_nil(activeSkillSet)
211+
assert.is_same(expectedName, activeSkillSet.title)
212+
assert.is_not_nil(activeConfigSet)
213+
assert.is_same(expectedName, activeConfigSet.title)
214+
end
215+
216+
it("does not reorder loadouts when oldIndex is the same as newIndex", function()
217+
build:NewLoadout("Loadout A")
218+
build:NewLoadout("Loadout B")
219+
build:NewLoadout("Loadout C")
220+
build.modFlag = false
221+
222+
build:SetActiveLoadout(build:GetLoadoutByName("Loadout A"))
223+
224+
local spec = build.treeTab.specList[2]
225+
t_remove(build.treeTab.specList, 2)
226+
t_insert(build.treeTab.specList, 2, spec)
227+
build:ReorderLoadout(2, 2)
228+
229+
assert.is_same(4, #build.treeTab.specList)
230+
assert.is_same("Loadout A", build.treeTab.specList[2].title)
231+
assertActiveLoadoutByName("Loadout A")
232+
assert.is_false(build.modFlag)
233+
end)
234+
235+
it("reorders loadouts when oldIndex is less than newIndex and activeSpec is at oldIndex", function()
236+
build:NewLoadout("Loadout A")
237+
build:NewLoadout("Loadout B")
238+
build:NewLoadout("Loadout C")
239+
build.modFlag = false
240+
241+
build:SetActiveLoadout(build:GetLoadoutByName("Loadout A"))
242+
243+
local spec = build.treeTab.specList[2]
244+
t_remove(build.treeTab.specList, 2)
245+
t_insert(build.treeTab.specList, 4, spec)
246+
build:ReorderLoadout(2, 4)
247+
248+
assert.is_same(4, #build.treeTab.specList)
249+
assert.is_same("Loadout A", build.treeTab.specList[4].title)
250+
assertActiveLoadoutByName("Loadout A")
251+
assert.is_true(build.modFlag)
252+
end)
253+
254+
it("reorders loadouts when oldIndex is less than newIndex and activeSpec is before oldIndex", function()
255+
build:NewLoadout("Loadout A")
256+
build:NewLoadout("Loadout B")
257+
build:NewLoadout("Loadout C")
258+
build.modFlag = false
259+
260+
build:SetActiveLoadout(build:GetLoadoutByName("Loadout C"))
261+
262+
local spec = build.treeTab.specList[2]
263+
t_remove(build.treeTab.specList, 2)
264+
t_insert(build.treeTab.specList, 3, spec)
265+
build:ReorderLoadout(2, 3)
266+
267+
assert.is_same(4, #build.treeTab.specList)
268+
assert.is_same("Loadout A", build.treeTab.specList[3].title)
269+
assertActiveLoadoutByName("Loadout C")
270+
assert.is_true(build.modFlag)
271+
end)
272+
273+
it("reorders loadouts when oldIndex is less than newIndex and activeSpec is after oldIndex", function()
274+
build:NewLoadout("Loadout A")
275+
build:NewLoadout("Loadout B")
276+
build:NewLoadout("Loadout C")
277+
build.modFlag = false
278+
279+
build:SetActiveLoadout(build:GetLoadoutByName("Loadout B"))
280+
281+
local spec = build.treeTab.specList[2]
282+
t_remove(build.treeTab.specList, 2)
283+
t_insert(build.treeTab.specList, 4, spec)
284+
build:ReorderLoadout(2, 4)
285+
286+
assert.is_same(4, #build.treeTab.specList)
287+
assert.is_same("Loadout A", build.treeTab.specList[4].title)
288+
assertActiveLoadoutByName("Loadout B")
289+
assert.is_true(build.modFlag)
290+
end)
291+
292+
it("reorders loadouts when oldIndex is greater than newIndex and activeSpec is at oldIndex", function()
293+
build:NewLoadout("Loadout A")
294+
build:NewLoadout("Loadout B")
295+
build:NewLoadout("Loadout C")
296+
build.modFlag = false
297+
298+
build:SetActiveLoadout(build:GetLoadoutByName("Loadout C"))
299+
300+
local spec = build.treeTab.specList[4]
301+
t_remove(build.treeTab.specList, 4)
302+
t_insert(build.treeTab.specList, 2, spec)
303+
build:ReorderLoadout(4, 2)
304+
305+
assert.is_same(4, #build.treeTab.specList)
306+
assert.is_same("Loadout C", build.treeTab.specList[2].title)
307+
assertActiveLoadoutByName("Loadout C")
308+
assert.is_true(build.modFlag)
309+
end)
310+
311+
it("reorders loadouts when oldIndex is greater than newIndex and activeSpec is before newIndex", function()
312+
build:NewLoadout("Loadout A")
313+
build:NewLoadout("Loadout B")
314+
build:NewLoadout("Loadout C")
315+
build.modFlag = false
316+
317+
build:SetActiveLoadout(build:GetLoadoutByName("Loadout B"))
318+
319+
local spec = build.treeTab.specList[4]
320+
t_remove(build.treeTab.specList, 4)
321+
t_insert(build.treeTab.specList, 2, spec)
322+
build:ReorderLoadout(4, 2)
323+
324+
assert.is_same(4, #build.treeTab.specList)
325+
assert.is_same("Loadout C", build.treeTab.specList[2].title)
326+
assertActiveLoadoutByName("Loadout B")
327+
assert.is_true(build.modFlag)
328+
end)
329+
330+
it("reorders loadouts when oldIndex is greater than newIndex and activeSpec is after newIndex", function()
331+
build:NewLoadout("Loadout A")
332+
build:NewLoadout("Loadout B")
333+
build:NewLoadout("Loadout C")
334+
build.modFlag = false
335+
336+
build:SetActiveLoadout(build:GetLoadoutByName("Loadout A"))
337+
338+
local spec = build.treeTab.specList[4]
339+
t_remove(build.treeTab.specList, 4)
340+
t_insert(build.treeTab.specList, 3, spec)
341+
build:ReorderLoadout(4, 3)
342+
343+
assert.is_same(4, #build.treeTab.specList)
344+
assert.is_same("Loadout C", build.treeTab.specList[3].title)
345+
assertActiveLoadoutByName("Loadout A")
346+
assert.is_true(build.modFlag)
347+
end)
348+
end)
198349
end)
199350

200351
describe("BuildSetService", function()

src/Classes/BuildSetService.lua

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,5 @@ function BuildSetServiceClass:CustomLoadout(specId, itemSetId, skillSetId, confi
4444
end
4545

4646
function BuildSetServiceClass:ReorderLoadout(oldIndex, newIndex)
47-
if oldIndex < newIndex then
48-
if oldIndex > self.buildMode.treeTab.activeSpec or newIndex < self.buildMode.treeTab.activeSpec then
49-
return
50-
end
51-
52-
if oldIndex == self.buildMode.treeTab.activeSpec then
53-
self.buildMode:SetActiveLoadout(self.buildMode:GetLoadoutByName(self.buildMode.treeTab.specList[newIndex]
54-
.title or "Default"))
55-
elseif newIndex >= self.buildMode.treeTab.activeSpec then
56-
self.buildMode:SetActiveLoadout(self.buildMode:GetLoadoutByName(self.buildMode.treeTab.specList
57-
[self.buildMode.treeTab.activeSpec - 1].title or "Default"))
58-
end
59-
else
60-
if oldIndex < self.buildMode.treeTab.activeSpec or newIndex > self.buildMode.treeTab.activeSpec then
61-
return
62-
end
63-
64-
if oldIndex == self.buildMode.treeTab.activeSpec then
65-
self.buildMode:SetActiveLoadout(self.buildMode:GetLoadoutByName(self.buildMode.treeTab.specList[newIndex]
66-
.title or "Default"))
67-
elseif newIndex <= self.buildMode.treeTab.activeSpec then
68-
self.buildMode:SetActiveLoadout(self.buildMode:GetLoadoutByName(self.buildMode.treeTab.specList
69-
[self.buildMode.treeTab.activeSpec + 1].title or "Default"))
70-
end
71-
end
47+
self.buildMode:ReorderLoadout(oldIndex, newIndex)
7248
end

src/Modules/Build.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,38 @@ function buildMode:SetActiveLoadout(loadout)
10051005
self:SyncLoadouts()
10061006
end
10071007

1008+
function buildMode:ReorderLoadout(oldIndex, newIndex)
1009+
if oldIndex == newIndex then
1010+
return
1011+
end
1012+
1013+
self.modFlag = true
1014+
1015+
if oldIndex < newIndex then
1016+
if oldIndex > self.treeTab.activeSpec or newIndex < self.treeTab.activeSpec then
1017+
return
1018+
end
1019+
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
1030+
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
1037+
end
1038+
end
1039+
10081040
function buildMode:EstimatePlayerProgress()
10091041
local PointsUsed, AscUsed, SecondaryAscUsed = self.spec:CountAllocNodes()
10101042
local extra = self.calcsTab.mainOutput and self.calcsTab.mainOutput.ExtraPoints or 0

0 commit comments

Comments
 (0)