Skip to content

Commit

Permalink
Merge branch 'main' into aoe-mgi-refactor-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbergen authored Sep 17, 2024
2 parents 75cb25d + 6e44cab commit 53c4e2d
Show file tree
Hide file tree
Showing 57 changed files with 925 additions and 2,556 deletions.
5 changes: 2 additions & 3 deletions components/game_table/commons/game_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ local Class = require('Module:Class')
local Game = require('Module:Game')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Table = require('Module:Table')
local VodLink = require('Module:VodLink')

local MatchTable = Lua.import('Module:MatchTable')

local NP_STATUSES = {'skip', 'np', 'canceled', 'cancelled'}
local NOT_PLAYED = 'np'
local SCORE_CONCAT = ' : '

---@class GameTableMatch: MatchTableMatch
Expand All @@ -32,7 +31,7 @@ end)
---@return match2game?
function GameTable:gameFromRecord(game)
if self.countGames == self.config.limit then return nil end
if Table.includes(NP_STATUSES, game.resulttype) then
if game.resulttype == NOT_PLAYED then
return nil
end

Expand Down
8 changes: 3 additions & 5 deletions components/infobox/commons/infobox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local Lua = require('Module:Lua')
local Variables = require('Module:Variables')
local WarningBox = require('Module:WarningBox')

local WidgetFactory = Lua.import('Module:Widget/Factory')
local Widget = Lua.import('Module:Widget')

---@class Infobox
---@field frame Frame?
Expand Down Expand Up @@ -82,11 +82,9 @@ end
---@return Html
function Infobox:build(widgets)
for _, widget in ipairs(widgets) do
if widget == nil or widget['is_a'] == nil then
error('Infobox:build can only accept Widgets')
end
assert(Class.instanceOf(widget, Widget), 'Infobox:build can only accept Widgets')

self.content:node(WidgetFactory.work(widget, self.injector))
self.content:node(widget:tryMake(self.injector))
end

self.root:node(self.content)
Expand Down
11 changes: 10 additions & 1 deletion components/match2/commons/match.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ end
---and removes direct references between a match record and its subobject records.
---@param match table
---@return {matchRecord: table, gameRecords: table[], opponentRecords: table[], playerRecords: table[]}
---@overload fun(match: table): {}
---@overload fun(match: any): {}
function Match.splitRecordsByType(match)
if match == nil or type(match) ~= 'table' then
return {}
Expand Down Expand Up @@ -385,6 +385,14 @@ end
function Match._prepareGameRecordForStore(matchRecord, gameRecord)
gameRecord.parent = matchRecord.parent
gameRecord.tournament = matchRecord.tournament
if not gameRecord.participants and gameRecord.opponents then
gameRecord.participants = {}
for opponentId, opponent in ipairs(gameRecord.opponents) do
for playerId, player in pairs(opponent.players) do
gameRecord.participants[opponentId .. '_' .. playerId] = player
end
end
end
Match.clampFields(gameRecord, Match.gameFields)
end

Expand Down Expand Up @@ -452,6 +460,7 @@ Match.gameFields = Table.map({
'parent',
'participants',
'patch',
'opponents', -- Not a real field yet, but will be in the future. Also for use in Match/Legacy
'resulttype',
'rounds',
'scores',
Expand Down
26 changes: 8 additions & 18 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ local ASSUME_FINISHED_AFTER = {
EXACT = 30800,
ESTIMATE = 86400,
}
MatchGroupInputUtil.ASSUME_FINISHED_AFTER = ASSUME_FINISHED_AFTER

local NOW = os.time()
local contentLanguage = mw.getContentLanguage()
Expand All @@ -114,7 +115,6 @@ local contentLanguage = mw.getContentLanguage()
---@field maxNumPlayers integer?
---@field resolveRedirect boolean?
---@field pagifyTeamNames boolean?
---@field pagifyPlayerNames boolean?

---@class MatchGroupInputSubstituteInformation
---@field substitute standardPlayer
Expand Down Expand Up @@ -236,11 +236,9 @@ function MatchGroupInputUtil.readOpponent(match, opponentIndex, options)
)
end

if options.pagifyPlayerNames then
Array.forEach(opponent.players or {}, function(player)
player.pageName = Page.pageifyLink(player.pageName)
end)
end
Array.forEach(opponent.players or {}, function(player)
player.pageName = Page.pageifyLink(player.pageName)
end)

local record = MatchGroupInputUtil.mergeRecordWithOpponent(opponentInput, opponent, substitutions)

Expand Down Expand Up @@ -1134,32 +1132,24 @@ function MatchGroupInputUtil.findPlayerId(players, playerInput, playerLink)
end

---@param name string
---@param options {pagifyPlayerNames: boolean?}?
---@return string
function MatchGroupInputUtil.makeLinkFromName(name, options)
local link = mw.ext.TeamLiquidIntegration.resolve_redirect(name)

if (options or {}).pagifyPlayerNames then
link = Page.pageifyLink(link) --[[@as string]]
end

return link
function MatchGroupInputUtil.makeLinkFromName(name)
return Page.pageifyLink(name) --[[@as string]]
end

---@alias PlayerInputData {name: string?, link: string?}
---@param playerIds MGIParsedPlayer[]
---@param inputPlayers table[]
---@param indexToPlayer fun(playerIndex: integer): PlayerInputData?
---@param transform fun(playerIndex: integer, playerIdData: MGIParsedPlayer?, playerInputData: PlayerInputData): table?
---@param options {pagifyPlayerNames: boolean?}?
---@return table, table
function MatchGroupInputUtil.parseParticipants(playerIds, inputPlayers, indexToPlayer, transform, options)
function MatchGroupInputUtil.parseParticipants(playerIds, inputPlayers, indexToPlayer, transform)
local participants = {}
local unattachedParticipants = {}
local function parsePlayer(_, playerIndex)
local playerInputData = indexToPlayer(playerIndex) or {}
if playerInputData.name and not playerInputData.link then
playerInputData.link = MatchGroupInputUtil.makeLinkFromName(playerInputData.name, options)
playerInputData.link = MatchGroupInputUtil.makeLinkFromName(playerInputData.name)
end
local playerId = MatchGroupInputUtil.findPlayerId(playerIds, playerInputData.name, playerInputData.link)
local toStoreData = transform(playerIndex, playerIds[playerId] or {}, playerInputData)
Expand Down

This file was deleted.

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

local DeprecatedCustomMatchGroupInput = Lua.import('Module:MatchGroup/Input/Starcraft/deprecated')
local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')
local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
Expand All @@ -25,7 +24,6 @@ local Streams = Lua.import('Module:Links/Stream')
local OPPONENT_CONFIG = {
resolveRedirect = true,
pagifyTeamNames = true,
pagifyPlayerNames = true,
}
local TBD = 'TBD'
local TBA = 'TBA'
Expand All @@ -34,20 +32,23 @@ local MODE_MIXED = 'mixed'
local StarcraftMatchGroupInput = {}
local MatchFunctions = {}
local MapFunctions = {}
-- make these available for ffa
StarcraftMatchGroupInput.MatchFunctions = MatchFunctions
StarcraftMatchGroupInput.MapFunctions = MapFunctions

---@param match table
---@param options table?
---@return table
function StarcraftMatchGroupInput.processMatch(match, options)
if Logic.readBool(match.ffa) then
return DeprecatedCustomMatchGroupInput.processMatch(match, options)
-- have to import here to avoid import loops
local FfaStarcraftMatchGroupInput = Lua.import('Module:MatchGroup/Input/Starcraft/Ffa')
return FfaStarcraftMatchGroupInput.processMatch(match, options)
end

Table.mergeInto(match, MatchFunctions.readDate(match.date))

local opponents = Array.mapIndexes(function(opponentIndex)
return MatchGroupInputUtil.readOpponent(match, opponentIndex, OPPONENT_CONFIG)
end)
local opponents = MatchFunctions.readOpponents(match)

-- TODO: check how we can get rid of this legacy stuff ...
Array.forEach(opponents, function(opponent, opponentIndex)
Expand All @@ -57,17 +58,6 @@ function StarcraftMatchGroupInput.processMatch(match, options)
match.winner = match.winner or opponentIndex
end)

Array.forEach(opponents, function(opponent)
opponent.extradata = opponent.extradata or {}
Table.mergeInto(opponent.extradata, MatchFunctions.getOpponentExtradata(opponent))
-- make sure match2players is not nil to avoid indexing nil
opponent.match2players = opponent.match2players or {}
Array.forEach(opponent.match2players, function(player)
player.extradata = player.extradata or {}
player.extradata.faction = MatchFunctions.getPlayerFaction(player)
end)
end)

local games = MatchFunctions.extractMaps(match, opponents)

local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games)
Expand Down Expand Up @@ -116,6 +106,27 @@ function StarcraftMatchGroupInput.processMatch(match, options)
return match
end

---@param match table
---@return table[]
function MatchFunctions.readOpponents(match)
local opponents = Array.mapIndexes(function(opponentIndex)
return MatchGroupInputUtil.readOpponent(match, opponentIndex, OPPONENT_CONFIG)
end)

Array.forEach(opponents, function(opponent)
opponent.extradata = opponent.extradata or {}
Table.mergeInto(opponent.extradata, MatchFunctions.getOpponentExtradata(opponent))
-- make sure match2players is not nil to avoid indexing nil
opponent.match2players = opponent.match2players or {}
Array.forEach(opponent.match2players, function(player)
player.extradata = player.extradata or {}
player.extradata.faction = MatchFunctions.getPlayerFaction(player)
end)
end)

return opponents
end

---@param dateInput string?
---@return {date: string, dateexact: boolean, timestamp: integer, timezoneId: string?, timezoneOffset: string?}
function MatchFunctions.readDate(dateInput)
Expand Down Expand Up @@ -399,8 +410,7 @@ function MapFunctions.getTeamParticipants(mapInput, opponent, opponentIndex)
flag = Flags.CountryName(playerIdData.flag),
position = playerIndex,
}
end,
OPPONENT_CONFIG
end
)

Array.forEach(unattachedParticipants, function(participant)
Expand Down
Loading

0 comments on commit 53c4e2d

Please sign in to comment.