Skip to content

Commit

Permalink
Add isEmpty function to Module:Opponent (#3258)
Browse files Browse the repository at this point in the history
* add isEmpty and isBye functions to opponent module

* also check against blank opponents

* trailing whitespace

* Update opponent.lua

* typo

* Update opponent.lua

* Update components/opponent/commons/opponent.lua

* split out into #3264

* catch team tbd opponents

* switch to alternative

* add some comments

* Update components/opponent/commons/opponent.lua

Co-authored-by: Martin B <[email protected]>

* Update opponent.lua

---------

Co-authored-by: Rikard Blixt <[email protected]>
Co-authored-by: Martin B <[email protected]>
  • Loading branch information
3 people authored Sep 14, 2023
1 parent 8b112d4 commit ba166a2
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit ba166a2

Please sign in to comment.