diff --git a/spec/System/TestWeaponSetPoints_spec.lua b/spec/System/TestWeaponSetPoints_spec.lua new file mode 100644 index 0000000000..e4df20a3e8 --- /dev/null +++ b/spec/System/TestWeaponSetPoints_spec.lua @@ -0,0 +1,38 @@ +describe("WeaponSetPoints", function() + before_each(function() + newBuild() + end) + + -- The warning only reads the per-set counts from CountAllocNodes, so the + -- nodes are placed straight into allocNodes: allocating through the tree + -- would drag pathing into a test about which set gets named. + local function warningFor(set1Used, set2Used) + local id = 0 + for _ = 1, set1Used + set2Used do + id = id + 1 + build.spec.allocNodes["fake" .. id] = { + type = "Normal", + allocMode = id <= set1Used and 1 or 2, + } + end + build.controls.warnings.lines = { } + build:EstimatePlayerProgress() + for _, line in ipairs(build.controls.warnings.lines) do + if line:match("passives available") then + return line + end + end + end + + it("names weapon set 1 when set 1 has fewer points allocated", function() + assert.are.equals("You have 2 Weapon set 1 passives available", warningFor(1, 3)) + end) + + it("names weapon set 2 when set 2 has fewer points allocated", function() + assert.are.equals("You have 2 Weapon set 2 passives available", warningFor(3, 1)) + end) + + it("says nothing when both sets have the same number allocated", function() + assert.is_nil(warningFor(2, 2)) + end) +end) diff --git a/src/Modules/Build.lua b/src/Modules/Build.lua index e8b9a48140..4c1c6319ba 100644 --- a/src/Modules/Build.lua +++ b/src/Modules/Build.lua @@ -1049,9 +1049,12 @@ function buildMode:EstimatePlayerProgress() end if not warningsWeaponSet and weaponSet1Used ~= weaponSet2Used then + -- The set with fewer allocated points is the one with points to + -- spare, since a node allocated in both sets is only paid for once. InsertIfNew(self.controls.warnings.lines, string.format( - "You have %d Weapon set 2 passives available", - math.abs(weaponSet2Used - weaponSet1Used) + "You have %d Weapon set %d passives available", + math.abs(weaponSet2Used - weaponSet1Used), + weaponSet1Used < weaponSet2Used and 1 or 2 )) end