From ba166a2167624b6b47b6e4e049c7fcd9a2fb3773 Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Thu, 14 Sep 2023 16:22:19 +0200 Subject: [PATCH] Add `isEmpty` function to `Module:Opponent` (#3258) * 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 * Update opponent.lua --------- Co-authored-by: Rikard Blixt Co-authored-by: Martin B --- components/opponent/commons/opponent.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index 1e7e3e86e76..32336432c0c 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -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') @@ -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