Skip to content

Commit

Permalink
add handling to non ffa
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckeLucky committed Dec 22, 2024
1 parent 954dc8f commit b787bc6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 15 deletions.
68 changes: 53 additions & 15 deletions components/match2/wikis/autochess/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
local Array = require('Module:Array')
local Lua = require('Module:Lua')
local Operator = require('Module:Operator')
local Variables = require('Module:Variables')

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

local MapFunctions = {}
local DEFAULT_BESTOF = 3

local CustomMatchGroupInput = {}
local MatchFunctions = {
OPPONENT_CONFIG = {
resolveRedirect = true,
Expand All @@ -21,31 +24,70 @@ local MatchFunctions = {
},
DEFAULT_MODE = 'team'
}
local MapFunctions = {}

local FfaMatchFunctions = {
OPPONENT_CONFIG = {
resolveRedirect = true,
applyUnderScores = true,
maxNumPlayers = 4,
},
DEFAULT_MODE = 'team'
}
local FfaMapFunctions = {}

local CustomMatchGroupInput = {}

---@param match table
---@param options table?
---@return table
function CustomMatchGroupInput.processMatch(match, options)
return MatchGroupInputUtil.standardProcessFfaMatch(match, MatchFunctions)
return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, FfaMatchFunctions)
end

--
-- match related functions
--
-- "Normal" Match

---@param match table
---@param opponents table[]
---@return table[]
function MatchFunctions.extractMaps(match, opponents)
return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions)
end

---@param bestofInput string|integer?
---@return integer?
function MatchFunctions.getBestOf(bestofInput)
local bestof = tonumber(bestofInput)

if bestof then
Variables.varDefine('bestof', bestof)
return bestof
end

return tonumber(Variables.varDefault('bestof')) or DEFAULT_BESTOF
end

---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(maps)
return function(opponentIndex)
return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex)
end
end

--- FFA Match

---@param match table
---@param opponents table[]
---@param scoreSettings table
---@return table[]
function MatchFunctions.extractMaps(match, opponents, scoreSettings)
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, MapFunctions)
function FfaMatchFunctions.extractMaps(match, opponents, scoreSettings)
return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, FfaMapFunctions)
end

---@param opponents table[]
---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(opponents, maps)
function FfaMatchFunctions.calculateMatchScore(opponents, maps)
return function(opponentIndex)
return Array.reduce(Array.map(maps, function(map)
return map.opponents[opponentIndex].score or 0
Expand All @@ -58,22 +100,18 @@ end
---@param opponents table[]
---@param settings table
---@return table
function MatchFunctions.getExtraData(match, games, opponents, settings)
function FfaMatchFunctions.getExtraData(match, games, opponents, settings)
return {
placementinfo = settings.placementInfo,
settings = settings.settings,
}
end

--
-- map related functions
--

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(match, map, opponents)
function FfaMapFunctions.getExtraData(match, map, opponents)
return {
dateexact = map.dateexact,
comment = map.comment,
Expand Down
38 changes: 38 additions & 0 deletions components/match2/wikis/autochess/match_summary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
-- @Liquipedia
-- wiki=autochess
-- page=Module:MatchSummary
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Lua = require('Module:Lua')

local MatchSummary = Lua.import('Module:MatchSummary/Base')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local WidgetUtil = Lua.import('Module:Widget/Util')

local CustomMatchSummary = {}

---@param args table
---@return Html
function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return Widget?
function CustomMatchSummary.createGame(date, game, gameIndex)
return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
children = WidgetUtil.collect(
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
MatchSummaryWidgets.GameCenter{children = 'Game ' .. gameIndex},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2}
)
}
end

return CustomMatchSummary

0 comments on commit b787bc6

Please sign in to comment.