From 16a744382ea80766cf912131038248fbbd0bd79b Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Sun, 3 Sep 2023 15:07:49 +0200 Subject: [PATCH 01/13] add isEmpty and isBye functions to opponent module --- components/opponent/commons/opponent.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index 130b1546cf6..8ae1d10975b 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -17,6 +17,8 @@ local TypeUtil = require('Module:TypeUtil') local PlayerExt = Lua.requireIfExists('Module:Player/Ext/Custom', {requireDevIfEnabled = true}) or Lua.import('Module:Player/Ext', {requireDevIfEnabled = true}) +local BYE = 'bye' + --[[ Structural type representation of an opponent. @@ -167,6 +169,25 @@ function Opponent.isTbd(opponent) end end +---Checks if an opponent is empty +---@param opponent standardOpponent? +---@return boolean +function Opponent.isEmpty(opponent) + local opponentCopy = Table.copy(opponent or {}) + --remove type since it might be set while the opponent is empty otherwise + opponentCopy.type = nil + + return Table.isEmpty(opponentCopy) +end + +---Checks whether an opponent is a BYE Opponent +---@param opponent standardOpponent +---@return boolean +function Opponent.isBye(opponent) + return string.lower(opponent.name or '') == BYE + or string.lower(opponent.template or '') == BYE +end + ---Checks if a player is a TBD player ---@param player standardPlayer ---@return boolean From ff9cb6fc3750d7dce436c641ffe14e24d3cad72e Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Sun, 3 Sep 2023 15:12:24 +0200 Subject: [PATCH 02/13] also check against blank opponents --- components/opponent/commons/opponent.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index 8ae1d10975b..95233946046 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -177,7 +177,7 @@ function Opponent.isEmpty(opponent) --remove type since it might be set while the opponent is empty otherwise opponentCopy.type = nil - return Table.isEmpty(opponentCopy) + return Table.deepEquals(opponent, Opponent.blank(opponent.type)) or Table.isEmpty(opponentCopy) end ---Checks whether an opponent is a BYE Opponent From b9ccd6c57697ddeae7a9ec3be49077c5a52e1812 Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Sun, 3 Sep 2023 15:18:00 +0200 Subject: [PATCH 03/13] trailing whitespace --- components/opponent/commons/opponent.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index 95233946046..4d4b758fca8 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -174,7 +174,7 @@ end ---@return boolean function Opponent.isEmpty(opponent) local opponentCopy = Table.copy(opponent or {}) - --remove type since it might be set while the opponent is empty otherwise + --remove type since it might be set while the opponent is empty otherwise opponentCopy.type = nil return Table.deepEquals(opponent, Opponent.blank(opponent.type)) or Table.isEmpty(opponentCopy) From 5ca66ad84caf51c19a37112ff53579728dca62cf Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Sun, 3 Sep 2023 17:00:42 +0200 Subject: [PATCH 04/13] Update opponent.lua --- components/opponent/commons/opponent.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index 4d4b758fca8..00d6944c736 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -173,11 +173,15 @@ end ---@param opponent standardOpponent? ---@return boolean function Opponent.isEmpty(opponent) + if not opponnet.type or Table.deepEquals(opponent, Opponent.blank(opponent.type)) then + return true + end + local opponentCopy = Table.copy(opponent or {}) --remove type since it might be set while the opponent is empty otherwise opponentCopy.type = nil - return Table.deepEquals(opponent, Opponent.blank(opponent.type)) or Table.isEmpty(opponentCopy) + return Table.isEmpty(opponentCopy) end ---Checks whether an opponent is a BYE Opponent From a12e6e191be8d0470b0256cbc1f7f948c351e15d Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Sun, 3 Sep 2023 17:04:35 +0200 Subject: [PATCH 05/13] typo --- components/opponent/commons/opponent.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index 00d6944c736..22b8dcf2fba 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -173,7 +173,7 @@ end ---@param opponent standardOpponent? ---@return boolean function Opponent.isEmpty(opponent) - if not opponnet.type or Table.deepEquals(opponent, Opponent.blank(opponent.type)) then + if not opponent.type or Table.deepEquals(opponent, Opponent.blank(opponent.type)) then return true end From 42a4e7ff46f5e4d30d0ac891191cb68f3e690514 Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Sun, 3 Sep 2023 20:37:49 +0200 Subject: [PATCH 06/13] Update opponent.lua --- components/opponent/commons/opponent.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index 22b8dcf2fba..858f8fd1c12 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -173,7 +173,7 @@ end ---@param opponent standardOpponent? ---@return boolean function Opponent.isEmpty(opponent) - if not opponent.type or Table.deepEquals(opponent, Opponent.blank(opponent.type)) then + if not opponent or not opponent.type or Table.deepEquals(opponent, Opponent.blank(opponent.type)) then return true end From 94b48549bd29bb980a2d2938c502e0f22b941b7d Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Sun, 3 Sep 2023 20:40:37 +0200 Subject: [PATCH 07/13] Update components/opponent/commons/opponent.lua --- components/opponent/commons/opponent.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index 858f8fd1c12..5029d1a3ae9 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -177,7 +177,7 @@ function Opponent.isEmpty(opponent) return true end - local opponentCopy = Table.copy(opponent or {}) + local opponentCopy = Table.copy(opponent) --remove type since it might be set while the opponent is empty otherwise opponentCopy.type = nil From 26adc4ce60a699f16f499e1133f75939f734c409 Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Tue, 5 Sep 2023 09:13:18 +0200 Subject: [PATCH 08/13] split out into #3264 --- components/opponent/commons/opponent.lua | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index 5029d1a3ae9..e8d455ced56 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -17,8 +17,6 @@ local TypeUtil = require('Module:TypeUtil') local PlayerExt = Lua.requireIfExists('Module:Player/Ext/Custom', {requireDevIfEnabled = true}) or Lua.import('Module:Player/Ext', {requireDevIfEnabled = true}) -local BYE = 'bye' - --[[ Structural type representation of an opponent. @@ -184,14 +182,6 @@ function Opponent.isEmpty(opponent) return Table.isEmpty(opponentCopy) end ----Checks whether an opponent is a BYE Opponent ----@param opponent standardOpponent ----@return boolean -function Opponent.isBye(opponent) - return string.lower(opponent.name or '') == BYE - or string.lower(opponent.template or '') == BYE -end - ---Checks if a player is a TBD player ---@param player standardPlayer ---@return boolean From c52e172896a35d8a581fa88e883f9195a86cdf6b Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Tue, 5 Sep 2023 09:30:39 +0200 Subject: [PATCH 09/13] catch team tbd opponents --- components/opponent/commons/opponent.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index e8d455ced56..af2a4b3cb7c 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -171,7 +171,8 @@ end ---@param opponent standardOpponent? ---@return boolean function Opponent.isEmpty(opponent) - if not opponent or not opponent.type or Table.deepEquals(opponent, Opponent.blank(opponent.type)) then + if not opponent or not opponent.type or + (Table.deepEquals(opponent, Opponent.blank(opponent.type)) and not Opponent.isTbd(opponent)) then return true end From 5abe7c01716945c8ee286e912b74c078f17f832b Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Mon, 11 Sep 2023 08:49:16 +0200 Subject: [PATCH 10/13] switch to alternative --- components/opponent/commons/opponent.lua | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index fea2d27b76c..bb439afc64b 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -173,16 +173,9 @@ end ---@param opponent standardOpponent? ---@return boolean function Opponent.isEmpty(opponent) - if not opponent or not opponent.type or - (Table.deepEquals(opponent, Opponent.blank(opponent.type)) and not Opponent.isTbd(opponent)) then - return true - end - - local opponentCopy = Table.copy(opponent) - --remove type since it might be set while the opponent is empty otherwise - opponentCopy.type = nil - - return Table.isEmpty(opponentCopy) + return not opponent or not opponent.type + or (String.isEmpty(opponent.name) and String.isEmpty(opponent.template) and Table.isEmpty(opponent.players)) + or (not Opponent.isTbd(opponent) and Table.deepEquals(opponent, Opponent.blank(opponent.type))) end ---Checks whether an opponent is a BYE Opponent From 6d09ecb91452d39c01506f6dc97a6f75f47b9b04 Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Tue, 12 Sep 2023 11:49:39 +0200 Subject: [PATCH 11/13] add some comments --- components/opponent/commons/opponent.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index bb439afc64b..734ea2b0cc3 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -173,8 +173,12 @@ end ---@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 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 From 2191c65f70f43939ee9948bdfae108c9cf8d937d Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:26:58 +0200 Subject: [PATCH 12/13] Update components/opponent/commons/opponent.lua Co-authored-by: Martin B --- components/opponent/commons/opponent.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index 734ea2b0cc3..ae12e8b2c04 100644 --- a/components/opponent/commons/opponent.lua +++ b/components/opponent/commons/opponent.lua @@ -175,7 +175,7 @@ end 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 + -- 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 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` From 8717936b3d945c40f1cf9199b86476e037a4c9f4 Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Wed, 13 Sep 2023 15:56:52 +0200 Subject: [PATCH 13/13] Update opponent.lua --- components/opponent/commons/opponent.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/opponent/commons/opponent.lua b/components/opponent/commons/opponent.lua index ae12e8b2c04..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') @@ -176,10 +177,7 @@ 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 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))) + or (String.isEmpty(opponent.name) and String.isEmpty(opponent.template) and Logic.isDeepEmpty(opponent.players)) end ---Checks whether an opponent is a BYE Opponent