Skip to content

Commit

Permalink
Merge branch 'release/3.13.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
evil-morfar committed Sep 14, 2024
2 parents 1ddb91e + e05bb0a commit 29d2110
Show file tree
Hide file tree
Showing 29 changed files with 608 additions and 234 deletions.
4 changes: 3 additions & 1 deletion .specs/AddonLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ function Loader.LoadFiles(files)
if file:match("^Libs") then
dofile(FixAceGUIPaths(file))
else
loadfile(file)(ADDON_NAME, ADDON_OBJECT)
local fileFunc = loadfile(file)
if not fileFunc then error("File not found: " .. file) end
fileFunc(ADDON_NAME, ADDON_OBJECT)
end
end
end
Expand Down
271 changes: 179 additions & 92 deletions .specs/Classes/Utils/GroupLoot.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,98 +13,98 @@ local GroupLoot = addon.Require "Utils.GroupLoot"
addon:InitLogging()
addon.Print = function() end --noop
describe("#GroupLoot", function()
-- describe("#Basic", function()
-- it("should need on items when we're ML and item can be needed", function()
-- stub(_G, "GetLootRollItemInfo", function()
-- return nil,nil,nil,nil,nil,1 -- canNeed = true
-- end)
-- local s = spy.on(GroupLoot, "RollOnLoot")
-- SetupML()
-- GroupLoot:OnStartLootRoll(nil, 1)
-- assert.spy(s).was_called(1)
-- assert.spy(s).was_called_with(GroupLoot, 1, 1)
-- _G.GetLootRollItemInfo:revert()
-- end)
-- it("should greed on loot when we're ML", function()
-- local s = spy.on(GroupLoot, "RollOnLoot")
-- SetupML()
-- GroupLoot:OnStartLootRoll(nil, 1)
-- assert.spy(s).was_called(1)
-- assert.spy(s).was_called_with(GroupLoot, 1, 2)
-- end)
-- it("should pass on loot by default", function()
-- local s = spy.on(GroupLoot, "RollOnLoot")
-- SetupML()
-- addon.isMasterLooter = false
-- addon.isInGuildGroup = false
-- GroupLoot:OnStartLootRoll(nil, 1)
-- GroupLoot:OnStartLootRoll(nil, 2)
-- assert.spy(s).was_called(0)
-- end)

-- it("should not do anything when addon isn't in use", function()
-- local s = spy.on(GroupLoot, "RollOnLoot")
-- addon.handleLoot = false
-- GroupLoot:OnStartLootRoll(nil, 3)
-- assert.spy(s).was_called(0)
-- end)

-- it("should not do anything when addon is disabled", function()
-- local s = spy.on(GroupLoot, "RollOnLoot")
-- addon.enabled = false
-- GroupLoot:OnStartLootRoll(nil, 3)
-- assert.spy(s).was_called(0)
-- end)
-- end)

-- describe("#autoGroupLootGuildGroupOnly ", function()
-- local s
-- before_each(function()
-- s = spy.on(GroupLoot, "RollOnLoot")
-- addon.enabled = true
-- SetupML()
-- addon.isMasterLooter = false
-- end)
-- describe("enabled", function()
-- it("should pass on loot if in guild group", function()
-- addon.isInGuildGroup = true
-- GroupLoot:OnStartLootRoll(nil, 1)
-- GroupLoot:OnStartLootRoll(nil, 2)
-- assert.spy(s).was_called(2)
-- assert.spy(s).was_called_with(GroupLoot, 1, 0)
-- assert.spy(s).was_called_with(GroupLoot, 2, 0)
-- end)

-- it("should not pass on loot if not in guild group", function()
-- addon.isInGuildGroup = false
-- GroupLoot:OnStartLootRoll(nil, 1)
-- GroupLoot:OnStartLootRoll(nil, 2)
-- assert.spy(s).was_called(0)
-- end)
-- end)

-- describe("disabled", function()
-- addon.db.profile.autoGroupLootGuildGroupOnly = false
-- it("should pass on loot if in guild group", function()
-- addon.isInGuildGroup = true
-- GroupLoot:OnStartLootRoll(nil, 1)
-- GroupLoot:OnStartLootRoll(nil, 2)
-- assert.spy(s).was_called(2)
-- assert.spy(s).was_called_with(GroupLoot, 1, 0)
-- assert.spy(s).was_called_with(GroupLoot, 2, 0)
-- end)

-- it("should pass on loot if not in guild group", function()
-- addon.isInGuildGroup = false
-- GroupLoot:OnStartLootRoll(nil, 1)
-- GroupLoot:OnStartLootRoll(nil, 2)
-- assert.spy(s).was_called(2)
-- assert.spy(s).was_called_with(GroupLoot, 1, 0)
-- assert.spy(s).was_called_with(GroupLoot, 2, 0)
-- end)
-- end)

-- end)
describe("#Basic", function()
it("should need on items when we're ML and item can be needed", function()
stub(_G, "GetLootRollItemInfo", function()
return nil,nil,nil,nil,nil,1 -- canNeed = true
end)
local s = spy.on(GroupLoot, "RollOnLoot")
SetupML()
GroupLoot:OnStartLootRoll(nil, 1)
assert.spy(s).was_called(1)
assert.spy(s).was_called_with(GroupLoot, 1, 1)
_G.GetLootRollItemInfo:revert()
end)
it("should greed on loot when we're ML", function()
local s = spy.on(GroupLoot, "RollOnLoot")
SetupML()
GroupLoot:OnStartLootRoll(nil, 1)
assert.spy(s).was_called(1)
assert.spy(s).was_called_with(GroupLoot, 1, 2)
end)
it("should pass on loot by default", function()
local s = spy.on(GroupLoot, "RollOnLoot")
SetupML()
addon.isMasterLooter = false
addon.isInGuildGroup = false
GroupLoot:OnStartLootRoll(nil, 1)
GroupLoot:OnStartLootRoll(nil, 2)
assert.spy(s).was_called(0)
end)

it("should not do anything when addon isn't in use", function()
local s = spy.on(GroupLoot, "RollOnLoot")
addon.handleLoot = false
GroupLoot:OnStartLootRoll(nil, 3)
assert.spy(s).was_called(0)
end)

it("should not do anything when addon is disabled", function()
local s = spy.on(GroupLoot, "RollOnLoot")
addon.enabled = false
GroupLoot:OnStartLootRoll(nil, 3)
assert.spy(s).was_called(0)
end)
end)

describe("#autoGroupLootGuildGroupOnly ", function()
local s
before_each(function()
s = spy.on(GroupLoot, "RollOnLoot")
addon.enabled = true
SetupML()
addon.isMasterLooter = false
end)
describe("enabled", function()
it("should pass on loot if in guild group", function()
addon.isInGuildGroup = true
GroupLoot:OnStartLootRoll(nil, 1)
GroupLoot:OnStartLootRoll(nil, 2)
assert.spy(s).was_called(2)
assert.spy(s).was_called_with(GroupLoot, 1, 0)
assert.spy(s).was_called_with(GroupLoot, 2, 0)
end)

it("should not pass on loot if not in guild group", function()
addon.isInGuildGroup = false
GroupLoot:OnStartLootRoll(nil, 1)
GroupLoot:OnStartLootRoll(nil, 2)
assert.spy(s).was_called(0)
end)
end)

describe("disabled", function()
addon.db.profile.autoGroupLootGuildGroupOnly = false
it("should pass on loot if in guild group", function()
addon.isInGuildGroup = true
GroupLoot:OnStartLootRoll(nil, 1)
GroupLoot:OnStartLootRoll(nil, 2)
assert.spy(s).was_called(2)
assert.spy(s).was_called_with(GroupLoot, 1, 0)
assert.spy(s).was_called_with(GroupLoot, 2, 0)
end)

it("should pass on loot if not in guild group", function()
addon.isInGuildGroup = false
GroupLoot:OnStartLootRoll(nil, 1)
GroupLoot:OnStartLootRoll(nil, 2)
assert.spy(s).was_called(2)
assert.spy(s).was_called_with(GroupLoot, 1, 0)
assert.spy(s).was_called_with(GroupLoot, 2, 0)
end)
end)

end)

describe("#ignored items", function()
local s
Expand All @@ -121,6 +121,92 @@ describe("#GroupLoot", function()
end)
end)

describe("#Status", function()
--[[ Tested with integers, binary and string versions (100.000 reps):
String Time taken: 1.035
Normal Time taken: 0.819
Binary Time taken: 0.84
Binary is a bit slower than using integers, but uses less than half the size when transmitting.
]]
before_each(function()
addon.enabled = true
addon.handleLoot = false
addon.mldb = {}
addon.isMasterLooter = false
addon.masterLooter = nil
addon.isInGuildGroup = false
addon.db.profile.autoGroupLootGuildGroupOnly = true
end)
it("should return '101100000' by default", function()
local status = GroupLoot:GetInvertedStatusTable()
-- By default only GetNumGroupMembers, autoGroupLootGuildGroupOnly, and enabled are set
-- 101100000
local expected = GroupLoot:CalculateStatus("enabled", "autoGroupLootGuildGroupOnly", "numGroupMembers")
assert.equal(expected, GroupLoot:GetStatus())
end)

it("should return '101100001' when mldb is set", function()
addon.mldb = { autoGroupLoot = false, }
-- 101100001
local expected = GroupLoot:CalculateStatus("enabled", "autoGroupLootGuildGroupOnly", "numGroupMembers",
"mldb")
assert.equal(expected, GroupLoot:GetStatus())
end)
it("should return '101100011' when mldb.autoGroupLoot is enabled", function()
addon.mldb = { autoGroupLoot = true, }
-- 101100011
local expected = GroupLoot:CalculateStatus("enabled", "autoGroupLootGuildGroupOnly", "numGroupMembers",
"mldb", "mldb.autoGroupLoot")
assert.equal(expected, GroupLoot:GetStatus())
end)

it("should return '101100100' when handleLoot is enabled", function()
addon.handleLoot = true
-- 101100100
local expected = GroupLoot:CalculateStatus("enabled", "autoGroupLootGuildGroupOnly", "numGroupMembers",
"handleLoot")
assert.equal(expected, GroupLoot:GetStatus())
end)

it("should return '101111000' when someone else is ML", function()
addon.masterLooter = "Someone"
-- 101111000
local expected = GroupLoot:CalculateStatus("enabled", "autoGroupLootGuildGroupOnly", "numGroupMembers",
"masterLooter")
assert.equal(expected, GroupLoot:GetStatus())
end)

it("should return '101111000' when we're ML", function()
addon.isMasterLooter = true
addon.masterLooter = addon.player
-- 101111000
local expected = GroupLoot:CalculateStatus("enabled", "autoGroupLootGuildGroupOnly", "numGroupMembers",
"masterLooter", "isMasterLooter")
assert.equal(expected, GroupLoot:GetStatus())
end)

it("should return '11?101111' when we should pass", function()
addon.mldb = { autoGroupLoot = true, }
addon.handleLoot = true
addon.masterLooter = addon.player
addon.isInGuildGroup = true
assert.is.True(GroupLoot:ShouldPassOnLoot())
assert.is.False(GroupLoot:ShouldRollOnLoot())
assert.is.Equal(0x1af, bit.band(GroupLoot:GetStatus(), 0x1af))
assert.is.Equal(0, bit.band(GroupLoot:GetStatus(), 0x10))
end)
it("should return '11?111111' when we should roll", function()
addon.mldb = { autoGroupLoot = true, }
addon.handleLoot = true
addon.masterLooter = addon.player
addon.isMasterLooter = true
addon.isInGuildGroup = true
assert.is.False(GroupLoot:ShouldPassOnLoot())
assert.is.True(GroupLoot:ShouldRollOnLoot())
assert.is.Equal(0x1bf, bit.band(GroupLoot:GetStatus(), 0x1bf))
end)
end)

function _G.GetLootRollItemLink(rollID)
if GroupLoot.IgnoreList[rollID] then
return "item:" .. rollID .. ":"
Expand All @@ -129,6 +215,7 @@ describe("#GroupLoot", function()
end
end)

---@private
function _G.GetNumGroupMembers()
return 10
end
Expand Down
26 changes: 22 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
"Lua.runtime.path": [
"${workspace}/__tests/?.lua"
],

"Lua.workspace.library": [
"${3rd}/luassert/library",
"~/AppData/Roaming/Code/User/globalStorage/sumneko.lua/addonManager/addons/luassert/module/library",
"~/AppData/Roaming/Code/User/globalStorage/sumneko.lua/addonManager/addons/busted/module/library",
"${3rd}/lfs/library",
"~\\.vscode\\extensions\\ketho.wow-api-0.17.6\\Annotations"
],

"Lua.diagnostics.disable": [
"undefined-doc-name",
"missing-parameter"
],

"Lua.workspace.ignoreDir": [
".vscode",
"__tests"
],
"Lua.runtime.version": "Lua 5.1",
"Lua.runtime.builtin": {
"basic": "disable",
Expand All @@ -14,9 +32,7 @@
"table": "disable",
"utf8": "disable"
},
"Lua.workspace.library": [
"~\\.vscode\\extensions\\ketho.wow-api-0.17.6\\Annotations"
],

"Lua.diagnostics.globals": [
"lfs",
"ChatFrame_AddMessageEventFilter",
Expand Down Expand Up @@ -67,6 +83,8 @@
"tCompare",
"ContainsIf",
"ITEM_ACCOUNTBOUND_UNTIL_EQUIP",
"ChatFrame1"
"ChatFrame1",
"UISpecialFrames",
"tInsertUnique"
]
}
4 changes: 2 additions & 2 deletions Classes/Data/MLDB.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ local replacements = {
local replacements_inv = tInvert(replacements)

--- Gets a transmittable version of the MLDB
--- @param input MLDB @MLDB to convert. Defaults to addon MLDB.
--- @param input MLDB? @MLDB to convert. Defaults to addon MLDB.
---@return table @MLDB that's ready for transmit.
function MLDB:GetForTransmit(input)
local mldb = input or (private.isBuilt and private.mldb or private:BuildMLDB())
Expand All @@ -55,7 +55,7 @@ function MLDB:RestoreFromTransmit(input)
end

--- Sends the mldb to the target
--- @param target Player @The target to send to - defaults to "group"
--- @param target Player|"group" @The target to send to - defaults to "group"
function MLDB:Send(target)
Comms:Send {
target = target,
Expand Down
Loading

0 comments on commit 29d2110

Please sign in to comment.