Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isEmpty function to Module:Opponent #3258

Merged
merged 14 commits into from
Sep 14, 2023
11 changes: 11 additions & 0 deletions components/opponent/commons/opponent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

local Array = require('Module:Array')
local Flags = require('Module:Flags')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
Expand Down Expand Up @@ -169,6 +170,16 @@ function Opponent.isTbd(opponent)
end
end

---Checks if an opponent is empty
---@param opponent standardOpponent?
---@return boolean
function Opponent.isEmpty(opponent)
-- if no type is set consider opponent as empty
return not opponent or not opponent.type
-- if neither name nor template nor players are set consider the opponent as empty
or (String.isEmpty(opponent.name) and String.isEmpty(opponent.template) and Logic.isDeepEmpty(opponent.players))
end

---Checks whether an opponent is a BYE Opponent
---@param opponent standardOpponent
---@return boolean
Expand Down
Loading