-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
components/match2/wikis/deadlock/get_match_group_copy_paste_wiki.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
-- @Liquipedia | ||
-- wiki=deadlock | ||
-- page=Module:GetMatchGroupCopyPaste/wiki | ||
-- | ||
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
-- | ||
|
||
local Array = require('Module:Array') | ||
local Class = require('Module:Class') | ||
local Logic = require('Module:Logic') | ||
local Lua = require('Module:Lua') | ||
|
||
local BaseCopyPaste = Lua.import('Module:GetMatchGroupCopyPaste/wiki/Base') | ||
|
||
---@class DeadlockMatch2CopyPaste: Match2CopyPasteBase | ||
local WikiCopyPaste = Class.new(BaseCopyPaste) | ||
|
||
local INDENT = WikiCopyPaste.Indent | ||
|
||
function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args) | ||
local showScore = Logic.nilOr(Logic.readBoolOrNil, bestof == 0) | ||
|
||
local lines = Array.extend( | ||
'{{Match', | ||
Logic.readBool(args.needsWinner) and INDENT .. '|winner=' or nil, | ||
Array.map(Array.range(1, opponents), function(opponentIndex) | ||
return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste.getOpponent(mode, showScore) | ||
end), | ||
Logic.readBool(args.hasDate) and { | ||
INDENT .. '|date=', | ||
INDENT .. '|finished=', | ||
INDENT .. '|twitch=|youtube=' | ||
} or nil, | ||
Array.map(Array.range(1, bestof), function(mapIndex) | ||
return WikiCopyPaste._getMapCode(mapIndex) | ||
end), | ||
'}}' | ||
) | ||
|
||
return table.concat(lines, '\n') | ||
end | ||
|
||
---@param mapIndex integer | ||
---@return string | ||
function WikiCopyPaste._getMapCode(mapIndex) | ||
return table.concat(Array.extend( | ||
INDENT .. '|map' .. mapIndex .. '={{Map|length=|winner=|vod=', | ||
INDENT .. INDENT .. '|team1side=', | ||
INDENT .. INDENT .. '|t1h1=|t1h2=|t1h3=|t1h4=|t1h5=|t1h6=', | ||
INDENT .. INDENT .. '|team2side=', | ||
INDENT .. INDENT .. '|t2h1=|t2h2=|t2h3=|t2h4=|t2h5=|t2h6=', | ||
INDENT .. '}}' | ||
), '\n') | ||
end | ||
|
||
return WikiCopyPaste |
181 changes: 181 additions & 0 deletions
181
components/match2/wikis/deadlock/match_group_input_custom.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
--- | ||
-- @Liquipedia | ||
-- wiki=deadlock | ||
-- page=Module:MatchGroup/Input/Custom | ||
-- | ||
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
-- | ||
|
||
local Array = require('Module:Array') | ||
local FnUtil = require('Module:FnUtil') | ||
local HeroNames = mw.loadData('Module:HeroNames') | ||
local Lua = require('Module:Lua') | ||
local Operator = require('Module:Operator') | ||
local Streams = require('Module:Links/Stream') | ||
local Table = require('Module:Table') | ||
|
||
local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') | ||
|
||
local OPPONENT_CONFIG = { | ||
resolveRedirect = true, | ||
pagifyTeamNames = true, | ||
pagifyPlayerNames = true, | ||
maxNumPlayers = 10, | ||
} | ||
|
||
local MatchFunctions = {} | ||
local MapFunctions = {} | ||
|
||
local CustomMatchGroupInput = {} | ||
|
||
---@param match table | ||
---@param options? {isMatchPage: boolean?} | ||
---@return table | ||
function CustomMatchGroupInput.processMatch(match, options) | ||
local finishedInput = match.finished --[[@as string?]] | ||
local winnerInput = match.winner --[[@as string?]] | ||
Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date)) | ||
|
||
local opponents = Array.mapIndexes(function(opponentIndex) | ||
return MatchGroupInputUtil.readOpponent(match, opponentIndex, OPPONENT_CONFIG) | ||
end) | ||
local games = MatchFunctions.extractMaps(match, opponents) | ||
match.bestof = MatchGroupInputUtil.getBestOf(match.bestof, games) | ||
|
||
local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games) | ||
and MatchFunctions.calculateMatchScore(games) | ||
or nil | ||
|
||
Array.forEach(opponents, function(opponent, opponentIndex) | ||
opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ | ||
walkover = match.walkover, | ||
winner = match.winner, | ||
opponentIndex = opponentIndex, | ||
score = opponent.score, | ||
}, autoScoreFunction) | ||
end) | ||
|
||
match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents) | ||
|
||
if match.finished then | ||
match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) | ||
match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents) | ||
match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents) | ||
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2) | ||
elseif MatchGroupInputUtil.isNotPlayed(winnerInput, finishedInput) then | ||
match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) | ||
match.winner = nil | ||
end | ||
|
||
MatchGroupInputUtil.getCommonTournamentVars(match) | ||
|
||
match.stream = Streams.processStreams(match) | ||
match.extradata = MatchFunctions.getExtraData(match) | ||
|
||
match.games = games | ||
match.opponents = opponents | ||
|
||
return match | ||
end | ||
|
||
---@param match table | ||
---@param opponents table[] | ||
---@return table[] | ||
function MatchFunctions.extractMaps(match, opponents) | ||
local maps = {} | ||
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do | ||
local finishedInput = map.finished --[[@as string?]] | ||
local winnerInput = map.winner --[[@as string?]] | ||
|
||
map.map = nil | ||
map.participants = MapFunctions.getParticipants(map, opponents) | ||
map.extradata = MapFunctions.getExtraData(map) | ||
|
||
map.finished = MatchGroupInputUtil.mapIsFinished(map) | ||
local opponentInfo = Array.map(opponents, function(_, opponentIndex) | ||
local score, status = MatchGroupInputUtil.computeOpponentScore({ | ||
walkover = map.walkover, | ||
winner = map.winner, | ||
opponentIndex = opponentIndex, | ||
score = map['score' .. opponentIndex], | ||
}, MapFunctions.calculateMapScore(map.winner, map.finished)) | ||
return {score = score, status = status} | ||
end) | ||
|
||
map.scores = Array.map(opponentInfo, Operator.property('score')) | ||
if map.finished or MatchGroupInputUtil.isNotPlayed(map.winner, finishedInput) then | ||
map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo) | ||
map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo) | ||
map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo) | ||
end | ||
|
||
table.insert(maps, map) | ||
match[key] = nil | ||
end | ||
|
||
return maps | ||
end | ||
|
||
CustomMatchGroupInput.processMap = FnUtil.identity | ||
|
||
---@param maps table[] | ||
---@return fun(opponentIndex: integer): integer | ||
function MatchFunctions.calculateMatchScore(maps) | ||
return function(opponentIndex) | ||
return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex) | ||
end | ||
end | ||
|
||
---@param match table | ||
---@return table | ||
function MatchFunctions.getExtraData(match) | ||
return { | ||
comment = match.comment, | ||
} | ||
end | ||
|
||
---@param map table | ||
---@return table | ||
function MapFunctions.getExtraData(map) | ||
local extraData = { | ||
comment = map.comment, | ||
team1side = map.team1side, | ||
team2side = map.team2side, | ||
} | ||
|
||
return extraData | ||
end | ||
|
||
---@param map table | ||
---@param opponents table[] | ||
---@return table | ||
function MapFunctions.getParticipants(map, opponents) | ||
local participants = {} | ||
local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, HeroNames) | ||
|
||
for opponentIndex in ipairs(opponents) do | ||
for _, hero, playerIndex in Table.iter.pairsByPrefix(map, 't' .. opponentIndex .. 'h', {requireIndex = true}) do | ||
participants[opponentIndex .. '_' .. playerIndex] = { | ||
character = getCharacterName(hero), | ||
} | ||
end | ||
end | ||
|
||
return participants | ||
end | ||
|
||
---@param winnerInput string|integer|nil | ||
---@param finished boolean | ||
---@return fun(opponentIndex: integer): integer? | ||
function MapFunctions.calculateMapScore(winnerInput, finished) | ||
local winner = tonumber(winnerInput) | ||
return function(opponentIndex) | ||
-- TODO Better to check if map has started, rather than finished, for a more correct handling | ||
if not winner and not finished then | ||
return | ||
end | ||
return winner == opponentIndex and 1 or 0 | ||
end | ||
end | ||
|
||
return CustomMatchGroupInput |
Oops, something went wrong.