diff --git a/lua/wikis/deltaforce/GetMatchGroupCopyPaste/wiki.lua b/lua/wikis/deltaforce/GetMatchGroupCopyPaste/wiki.lua index 2a5d831db7d..48de5cdd652 100644 --- a/lua/wikis/deltaforce/GetMatchGroupCopyPaste/wiki.lua +++ b/lua/wikis/deltaforce/GetMatchGroupCopyPaste/wiki.lua @@ -53,7 +53,7 @@ function WikiCopyPaste.getStandardMatchCode(bestof, mode, index, opponents, args return INDENT .. '|opponent' .. opponentIndex .. '=' .. opponent end), bestof ~= 0 and Array.map(Array.range(1, bestof), function(mapIndex) - return INDENT .. '|map' .. mapIndex .. '={{Map|map=|score1=|score2=|winner=}}' + return INDENT .. '|map' .. mapIndex .. '={{Map|map=|team1side=|team2side=|winner=|vod=}}' end) or nil, INDENT .. '}}' ) diff --git a/lua/wikis/deltaforce/MatchGroup/Input/Custom.lua b/lua/wikis/deltaforce/MatchGroup/Input/Custom.lua index d1aeb41c537..ba057fb5b2c 100644 --- a/lua/wikis/deltaforce/MatchGroup/Input/Custom.lua +++ b/lua/wikis/deltaforce/MatchGroup/Input/Custom.lua @@ -9,27 +9,32 @@ local Lua = require('Module:Lua') local Array = Lua.import('Module:Array') local FnUtil = Lua.import('Module:FnUtil') +local Logic = Lua.import('Module:Logic') local Operator = Lua.import('Module:Operator') +local Variables = Lua.import('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') +local DEFAULT_BESTOF = 3 + local CustomMatchGroupInput = {} ----@class DeltaForceMatchParser: MatchParserInterface +---@class DeltaforceMatchParser: MatchParserInterface local MatchFunctions = { DEFAULT_MODE = 'team', - getBestOf = MatchGroupInputUtil.getBestOf, } ----@class DeltaForceMapParser: MapParserInterface -local MapFunctions = {} +---@class DeltaforceMapParser: MapParserInterface +local MapFunctions = { + BREAK_ON_EMPTY = true, +} ----@class DeltaForceFfaMatchParser: FfaMatchParserInterface +---@class DeltaforceFfaMatchParser: FfaMatchParserInterface local FfaMatchFunctions = { DEFAULT_MODE = 'team', } ----@class DeltaForceFfaMapParser: FfaMapParserInterface +---@class DeltaforceFfaMapParser: FfaMapParserInterface local FfaMapFunctions = {} ---@param match table @@ -47,12 +52,58 @@ function MatchFunctions.extractMaps(match, opponents) return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end +---@param bestofInput string|integer? +---@param games table[] +---@return integer? +function MatchFunctions.getBestOf(bestofInput, games) + local bestof = tonumber(bestofInput) + + if bestof then + Variables.varDefine('bestof', bestof) + return bestof + end + + return tonumber(Variables.varDefault('bestof')) or ((games and #games > 0) and #games) or DEFAULT_BESTOF +end + ---@param maps table[] ---@return fun(opponentIndex: integer): integer? function MatchFunctions.calculateMatchScore(maps) return FnUtil.curry(MatchGroupInputUtil.computeMatchScoreFromMapWinners, maps) end +---@param match table +---@param games table[] +---@param opponents MGIParsedOpponent[] +---@return table +function MatchFunctions.getExtraData(match, games, opponents) + return { + mapveto = MatchGroupInputUtil.getMapVeto(match), + mvp = MatchGroupInputUtil.readMvp(match, opponents), + } +end + + -- Parse map-side extradata (Attack/Defense) for use in MatchSummary +---@param match table +---@param map table +---@param opponents MGIParsedOpponent[] +---@return table +function MapFunctions.getExtraData(match, map, opponents) + if Logic.isEmpty(map.team1side) then + return {} + end + + local t1side = map.team1side:upper() + + return t1side == 'ATK' and { + t1side = 'ATK', + t2side = 'DEF', + } or t1side == 'DEF' and { + t1side = 'DEF', + t2side = 'ATK', + } or error('Invalid side specified: "' .. map.team1side .. '" (expected ATK or DEF)') +end + --- FFA Match ---@param match table diff --git a/lua/wikis/deltaforce/MatchSummary.lua b/lua/wikis/deltaforce/MatchSummary.lua index 60911d3df58..647e3a4e67d 100644 --- a/lua/wikis/deltaforce/MatchSummary.lua +++ b/lua/wikis/deltaforce/MatchSummary.lua @@ -9,13 +9,27 @@ local Lua = require('Module:Lua') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper') local MatchSummary = Lua.import('Module:MatchSummary/Base') + +local Html = Lua.import('Module:Widget/Html') +local Image = Lua.import('Module:Widget/Image/Icon/Image') local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All') local WidgetUtil = Lua.import('Module:Widget/Util') +local SIDE_ICONS = { + ATK = { + light = 'DF Attacker icon lightmode.png', + dark = 'DF Attacker icon darkmode.png', + }, + DEF = { + light = 'DF Defender icon lightmode.png', + dark = 'DF Defender icon darkmode.png', + }, +} + local CustomMatchSummary = {} ---@param args table ----@return Widget +---@return Renderable function CustomMatchSummary.getByMatchId(args) return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args) end @@ -23,8 +37,10 @@ end ---@param date string ---@param game MatchGroupUtilGame ---@param gameIndex integer ----@return Widget? +---@return Renderable? function CustomMatchSummary.createGame(date, game, gameIndex) + ---@param opponentIndex integer + ---@return Renderable[] local function makeTeamSection(opponentIndex) return { MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex}, @@ -32,12 +48,44 @@ function CustomMatchSummary.createGame(date, game, gameIndex) } end + ---@param opponentIndex integer + ---@return Renderable[]? + local function sideIndicator(opponentIndex) + local iconData = SIDE_ICONS[game.extradata['t' .. opponentIndex .. 'side']] + if not iconData then return end + return { + Html.Span{ + classes = {'brkts-popup-spaced'}, + children = Image{ + imageLight = iconData.light, + imageDark = iconData.dark, + size = '16px', + } + }, + Html.Span{ + css = { + ['font-size'] = '8px', + ['font-weight'] = 'bold', + margin = '0 -2px', + ['white-space'] = 'nowrap', + }, + children = game.extradata['t' .. opponentIndex .. 'side'], + } + } + end + return MatchSummaryWidgets.Row{ classes = {'brkts-popup-body-game'}, children = WidgetUtil.collect( - MatchSummaryWidgets.GameTeamWrapper{children = makeTeamSection(1)}, + MatchSummaryWidgets.GameTeamWrapper{children = WidgetUtil.collect( + makeTeamSection(1), + sideIndicator(1) + )}, MatchSummaryWidgets.GameCenter{children = DisplayHelper.Map(game)}, - MatchSummaryWidgets.GameTeamWrapper{children = makeTeamSection(2), flipped = true}, + MatchSummaryWidgets.GameTeamWrapper{children = WidgetUtil.collect( + makeTeamSection(2), + sideIndicator(2) + ), flipped = true}, MatchSummaryWidgets.GameComment{children = game.comment} ) }