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
13 changes: 13 additions & 0 deletions components/opponent/commons/opponent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ 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 not template not players are set consider the opponent as empty
hjpalpha marked this conversation as resolved.
Show resolved Hide resolved
or (String.isEmpty(opponent.name) and String.isEmpty(opponent.template) and Table.isEmpty(opponent.players))
-- if opponent equals blank consider it empty
-- need to exclude TBD Opponents since Opponet.blank sets a TBD Opponent for type `team`
or (not Opponent.isTbd(opponent) and Table.deepEquals(opponent, Opponent.blank(opponent.type)))
end

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