Skip to content

Commit

Permalink
refactor(match2): remove subobjects (#4850)
Browse files Browse the repository at this point in the history
* refactor(match2): remove subobjects

* unused imports

* simplify

* Apply suggestions from code review

Co-authored-by: hjpalpha <[email protected]>

* fix some legacy handling

* actually fix

---------

Co-authored-by: hjpalpha <[email protected]>
  • Loading branch information
Rathoz and hjpalpha authored Oct 15, 2024
1 parent 84aa23e commit 774b823
Show file tree
Hide file tree
Showing 56 changed files with 106 additions and 159 deletions.
3 changes: 1 addition & 2 deletions components/match2/commons/match_group_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ local Table = require('Module:Table')

local MatchGroup = Lua.import('Module:MatchGroup')
local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
local MatchSubobjects = Lua.import('Module:Match/Subobjects')

local globalVars = PageVariableNamespace()

Expand Down Expand Up @@ -248,7 +247,7 @@ function MatchGroupLegacy:handleMap(details, mapIndex)
map = self:_copyAndReplace(blueprint, details, true)
end

return MatchSubobjects.luaGetMap(map)
return map
end

---@param isReset boolean
Expand Down
43 changes: 0 additions & 43 deletions components/match2/commons/match_subobjects.lua

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ function MatchFunctions.extractMaps(match, opponents)
local maps = {}
local subGroup = 0
for mapKey, mapInput, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if Logic.isEmpty(mapInput) then
break
end
local map
map, subGroup = MapFunctions.readMap(mapInput, subGroup, #opponents)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ end
function CustomMatchGroupInput.extractMaps(match, opponents)
local maps = {}
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if map.map == nil and map.winner == nil then
break
end
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')

local DEFAULT_MODE = 'team'

local DUMMY_MAP_NAME = 'null' -- Is set in Template:Map when |map= is empty.
local OPPONENT_CONFIG = {
resolveRedirect = true,
applyUnderScores = true,
Expand Down Expand Up @@ -104,10 +103,6 @@ function MatchFunctions.extractMaps(match, opponents, scoreSettings)
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

if map.map == DUMMY_MAP_NAME then
map.map = ''
end

Table.mergeInto(map, MatchGroupInputUtil.readDate(map.date))
map.finished = MatchGroupInputUtil.mapIsFinished(map)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ local PageVariableNamespace = require('Module:PageVariableNamespace')
local Table = require('Module:Table')

local MatchGroupBase = Lua.import('Module:MatchGroup/Base')
local MatchSubobjects = Lua.import('Module:Match/Subobjects')

local globalVars = PageVariableNamespace()

Expand Down Expand Up @@ -72,7 +71,7 @@ function MatchMapsLegacy._readMaps(matchArgs)
score2 = Table.extract(matchArgs, prefix .. 'score2'),
vod = Table.extract(matchArgs, 'vodgame' .. mapIndex)
}
matchArgs[prefix] = Logic.isNotEmpty(mapArgs) and MatchSubobjects.luaGetMap(mapArgs) or nil
matchArgs[prefix] = Logic.isNotEmpty(mapArgs) and mapArgs or nil
end)
end

Expand Down
3 changes: 3 additions & 0 deletions components/match2/wikis/arenafps/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ end
function MatchFunctions.extractMaps(match, opponentCount)
local maps = {}
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if not map.map then
break
end
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ local Table = require('Module:Table')

local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')

local DUMMY_MAP = 'default' -- Is set in Template:Map when |map= is empty.
local OPPONENT_CONFIG = {
resolveRedirect = true,
pagifyTeamNames = true,
Expand Down Expand Up @@ -157,11 +156,10 @@ end
--

-- Check if a map should be discarded due to being redundant
-- DUMMY_MAP_NAME needs the match the default value in Template:Map
---@param map table
---@return boolean
function MapFunctions.keepMap(map)
return map.map ~= DUMMY_MAP
return map.map ~= nil
end

---@param map table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ end
function CustomMatchGroupInput.extractMaps(match, matchOpponents)
local maps = {}
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if not map.map then
break
end
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ local Template = require('Module:Template')
local CharacterNames = mw.loadData('Module:BrawlerNames')

local MatchGroupBase = Lua.import('Module:MatchGroup/Base')
local MatchSubobjects = Lua.import('Module:Match/Subobjects')

local globalVars = PageVariableNamespace()
local matchlistVars = PageVariableNamespace('LegacyMatchlist')
Expand Down Expand Up @@ -114,7 +113,7 @@ function MatchMapsLegacy._handleDetails(args, details)
score1 = Table.extract(details, prefix .. 'score1'),
score2 = Table.extract(details, prefix .. 'score2')
}
args[prefix] = MatchSubobjects.luaGetMap(map)
args[prefix] = map

if map and map.winner then
args.mapWinnersSet = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ end
function CustomMatchGroupInput.extractMaps(match, opponents)
local maps = {}
for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if map.map == nil then
break
end
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ local Template = require('Module:Template')

local Match = Lua.import('Module:Match')
local MatchGroup = Lua.import('Module:MatchGroup')
local MatchSubobjects = Lua.import('Module:Match/Subobjects')

local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
Expand Down Expand Up @@ -81,7 +80,7 @@ function MatchMapsLegacy._readMaps(matchArgs)
score1 = Table.extract(matchArgs, prefix .. 'score1'),
score2 = Table.extract(matchArgs, prefix .. 'score2'),
}
matchArgs[prefix] = Logic.isNotEmpty(mapArgs) and MatchSubobjects.luaGetMap(mapArgs) or nil
matchArgs[prefix] = Logic.nilIfEmpty(mapArgs)
end)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ end
function CustomMatchGroupInput.extractMaps(match, opponentCount)
local maps = {}
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if not map.map then
break
end
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ function MatchFunctions.extractMaps(match, opponents)
local maps = {}
local subGroup = 0
for mapKey, mapInput, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if Table.isEmpty(mapInput) then
break
end
local map
map, subGroup = MapFunctions.readMap(mapInput, mapIndex, subGroup, #opponents)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ local OpponentLibraries = Lua.import('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')

local DUMMY_MAP_NAME = 'null' -- Is set in Template:Map when |map= is empty.

local FEATURED_TIERS = {1, 2}
local MIN_EARNINGS_FOR_FEATURED = 200000

Expand Down Expand Up @@ -267,11 +265,10 @@ end
--

-- Check if a map should be discarded due to being redundant
-- DUMMY_MAP_NAME needs the match the default value in Template:Map
---@param map table
---@return boolean
function MapFunctions.keepMap(map)
return map.map ~= DUMMY_MAP_NAME
return map.map ~= nil
end

-- Parse extradata information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ local Variables = require('Module:Variables')
local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')

local DEFAULT_MODE = 'team'
local DUMMY_MAP = 'null' -- Is set in Template:Map when |map= is empty.
local SIDE_DEF = 'ct'
local SIDE_ATK = 't'

Expand Down Expand Up @@ -164,11 +163,10 @@ end
--

-- Check if a map should be discarded due to being redundant
-- DUMMY_MAP_NAME needs the match the default value in Template:Map
---@param map table
---@return boolean
function MapFunctions.keepMap(map)
return map.map ~= DUMMY_MAP
return map.map ~= nil
end

---@param map table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ end
function MatchFunctions.extractMaps(match, opponentCount)
local maps = {}
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if not map.map then
break
end
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local MatchGroupLegacyDefault = Class.new(MatchGroupLegacy)
---@return table
function MatchGroupLegacyDefault:getMap()
local map = {
['$notEmpty$'] = 'map$1$',
['$notEmpty$'] = 'map$1$winner',
map = 'map$1$',
team1side = 'map$1$team1side',
team2side = 'map$1$team2side',
Expand Down
7 changes: 2 additions & 5 deletions components/match2/wikis/dota2/legacy/match_maps_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ local Table = require('Module:Table')
local Template = require('Module:Template')

local MatchGroupBase = Lua.import('Module:MatchGroup/Base')
local MatchSubobjects = Lua.import('Module:Match/Subobjects')

local globalVars = PageVariableNamespace()
local matchlistVars = PageVariableNamespace('LegacyMatchlist')
Expand Down Expand Up @@ -49,7 +48,6 @@ function MatchMapsLegacy._convertMaps(args)
for key, value in pairs(map) do
args[mapKey .. key] = value
end
args[mapKey] = DEFAULT
args[matchKey] = nil
end
return args
Expand Down Expand Up @@ -102,16 +100,15 @@ function MatchMapsLegacy._handleDetails(args, details)
end)
end)
details[prefix] = nil
return MatchSubobjects.luaGetMap(map)
return map
end

local getMapOnlyWithWinner = function (index)
if not args['map' .. index .. 'win'] then
return nil
end
return MatchSubobjects.luaGetMap{
return {
winner = args['map' .. index .. 'win'],
map = DEFAULT
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ function CustomMatchGroupInput.extractMaps(match, opponents)
map.extradata = CustomMatchGroupInput.getMapExtraData(map, opponents, Logic.readBool(match.hasSubmatches))

map.opponents = CustomMatchGroupInput.getParticipants(map, opponents)
-- Match/Subobjects:luaGetMap sets a empty table as default value for participants.
-- Once subobjects have been refactored away this can be removed.
map.participants = nil

map.finished = MatchGroupInputUtil.mapIsFinished(map)
local opponentInfo = Array.map(opponents, function(_, opponentIndex)
Expand Down
4 changes: 0 additions & 4 deletions components/match2/wikis/fighters/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')
local Opponent = Lua.import('Module:Opponent')
local Streams = Lua.import('Module:Links/Stream')

local DUMMY_MAP_NAME = 'Null' -- Is set in Template:Map when |map= is empty.
local OPPONENT_CONFIG = {
resolveRedirect = true,
applyUnderScores = true,
Expand Down Expand Up @@ -89,9 +88,6 @@ function CustomMatchGroupInput.extractMaps(match, matchOpponents)
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

if map.map == DUMMY_MAP_NAME then
map.map = ''
end
map.extradata = {
comment = map.comment,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ end
function CustomMatchGroupInput.extractMaps(match, opponentCount)
local maps = {}
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if not map.map then
break
end
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Expand Down
3 changes: 3 additions & 0 deletions components/match2/wikis/halo/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ end
function MatchFunctions.extractMaps(match, opponentCount)
local maps = {}
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if not map.map then
break
end
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

Expand Down
3 changes: 1 addition & 2 deletions components/match2/wikis/heroes/legacy/match_maps_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ local Table = require('Module:Table')

local Match = Lua.import('Module:Match')
local MatchGroup = Lua.import('Module:MatchGroup')
local MatchSubobjects = Lua.import('Module:Match/Subobjects')

local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
Expand Down Expand Up @@ -94,7 +93,7 @@ function MatchMapsLegacy._readMaps(matchArgs)
if map and Logic.isEmpty(map.winner) then
map.winner = mapWinner
end
matchArgs['map' .. index] = map and MatchSubobjects.luaGetMap(map) or nil
matchArgs['map' .. index] = map
return map
end)
end
Expand Down
Loading

0 comments on commit 774b823

Please sign in to comment.