Skip to content

Commit

Permalink
feat: add support for smash in match2, prizepools and hdb (#5109)
Browse files Browse the repository at this point in the history
* feat: add support for smash in match2, prizepools and hdb

* display tweaks

* lint

* adjust based on feedback

* Support unknown remaining stock

* Make crew (team) matches look good also

* new display

* wip bracket display

* improve further

* fading out for loses

* 5112

* from review

* type safety and match parties according to specs
  • Loading branch information
Rathoz authored Dec 2, 2024
1 parent 9f2b5c8 commit ea5e7b6
Show file tree
Hide file tree
Showing 12 changed files with 938 additions and 2 deletions.
91 changes: 91 additions & 0 deletions components/hidden_data_box/wikis/smash/hidden_data_box_custom.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
-- @Liquipedia
-- wiki=smash
-- page=Module:HiddenDataBox/Custom
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Class = require('Module:Class')
local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local Tier = require('Module:Tier/Custom')
local Variables = require('Module:Variables')

local BasicHiddenDataBox = Lua.import('Module:HiddenDataBox')
local CustomHiddenDataBox = {}

local PAGE_TO_SECTION = {
['Singles Pools'] = 'Pools',
['Round 1 Pools'] = 'R1 Pools',
['Round 2 Pools'] = 'R2 Pools',
['Round 3 Pools'] = 'R3 Pools',
}

---@param args table
---@return Html
function CustomHiddenDataBox.run(args)
args = args or {}
args.liquipediatier = Tier.toNumber(args.liquipediatier)

BasicHiddenDataBox.addCustomVariables = CustomHiddenDataBox.addCustomVariables

return BasicHiddenDataBox.run(args)
end

---@param args table
---@param queryResult table
function CustomHiddenDataBox.addCustomVariables(args, queryResult)
if tonumber(args.phase) then
Variables.varDefine('num_missing_dates', 7200 * tonumber(args.phase))
end

Variables.varDefine('tournament_sdate', Variables.varDefault('tournament_startdate'))
Variables.varDefine('tournament_edate', Variables.varDefault('tournament_enddate'))
Variables.varDefine('tournament_date', Variables.varDefault('tournament_enddate'))

Variables.varDefine('tournament_link', Variables.varDefault('tournament_parent'))
Variables.varDefine('tournament_mode', Variables.varDefault('tournament_mode', 'singles'))

Variables.varDefine('tournament_entrants', queryResult.participantsnumber)
Variables.varDefine('tournament_region', queryResult.extradata.region)

Variables.varDefine('circuit', queryResult.extradata.circuit)
Variables.varDefine('circuit_tier', queryResult.extradata.circuit_tier or '')
Variables.varDefine('circuit2', queryResult.extradata.circuit2)
Variables.varDefine('circuit2_tier', queryResult.extradata.circuit2_tier or '')

Variables.varDefine('tournament_tier', Variables.varDefault('tournament_liquipediatier'))
Variables.varDefine('tournament_tiertype', Variables.varDefault('tournament_liquipediatiertype'))

Variables.varDefine('tournament_game', args.game or queryResult.game)

Variables.varDefine('matchsection',
args.section or CustomHiddenDataBox._determineMatchSection(mw.title.getCurrentTitle())
)

if Variables.varDefault('tournament_mode') == 'squad' then
Variables.varDefine('disableheads', 'true')
end

Variables.varDefine('notranked', String.nilIfEmpty(queryResult.extradata.notranked) or 'false')
end

---@param page Title
---@return string?
function CustomHiddenDataBox._determineMatchSection(page)
if page.subpageText == 'Singles Bracket' then
return 'Bracket'
end

local titleParts = mw.text.split(page.text , '/', true)

for key, section in pairs(PAGE_TO_SECTION) do
if Table.includes(titleParts, key) then
return section
end
end
end

return Class.export(CustomHiddenDataBox)
3 changes: 3 additions & 0 deletions components/infobox/wikis/smash/infobox_league_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local Array = require('Module:Array')
local Class = require('Module:Class')
local Currency = require('Module:Currency')
local Game = require('Module:Game')
local Json = require('Module:Json')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Table = require('Module:Table')
Expand Down Expand Up @@ -240,6 +241,8 @@ function CustomLeague:addToLpdb(lpdbData, args)
lpdbData.extradata.circuit_tier = args.circuittier
lpdbData.extradata.circuit2_tier = args.circuit2tier

Variables.varDefine('tournament_extradata', Json.stringify(lpdbData.extradata))

return lpdbData
end

Expand Down
42 changes: 42 additions & 0 deletions components/match2/wikis/smash/brkts_wiki_specific.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
-- @Liquipedia
-- wiki=smash
-- page=Module:Brkts/WikiSpecific
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local FnUtil = require('Module:FnUtil')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Table = require('Module:Table')

local BaseWikiSpecific = Lua.import('Module:Brkts/WikiSpecific/Base')

---@class SmashBrktsWikiSpecific: BrktsWikiSpecific
local WikiSpecific = Table.copy(BaseWikiSpecific)

WikiSpecific.matchFromRecord = FnUtil.lazilyDefineFunction(function()
local StarcraftMatchGroupUtil = Lua.import('Module:MatchGroup/Util/Custom')
return StarcraftMatchGroupUtil.matchFromRecord
end)

---@param matchGroupType string
---@return function
function WikiSpecific.getMatchGroupContainer(matchGroupType)
return matchGroupType == 'matchlist'
and Lua.import('Module:MatchGroup/Display/Matchlist').MatchlistContainer
or Lua.import('Module:MatchGroup/Display/Bracket/Custom').BracketContainer
end

---@param match table
---@return boolean
function WikiSpecific.matchHasDetails(match)
return match.dateIsExact
or Logic.isNotEmpty(match.vod)
or not Table.isEmpty(match.links)
or Logic.isNotEmpty(match.comment)
or 0 < #match.games
end

return WikiSpecific
61 changes: 61 additions & 0 deletions components/match2/wikis/smash/get_match_group_copy_paste_wiki.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
-- @Liquipedia
-- wiki=smash
-- 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')

---WikiSpecific Code for MatchList and Bracket Code Generators
---@class SmashMatchCopyPaste: Match2CopyPasteBase
local WikiCopyPaste = Class.new(BaseCopyPaste)

local INDENT = WikiCopyPaste.Indent

---returns the Code for a Match, depending on the input
---@param bestof integer
---@param mode string
---@param index integer
---@param opponents integer
---@param args table
---@return string
function WikiCopyPaste.getMatchCode(bestof, mode, index, opponents, args)
local showScore = Logic.nilOr(Logic.readBool(args.score), true)

local lines = Array.extend(
'{{Match|bestof=' .. bestof,
INDENT .. '|date=',
INDENT .. '|twitch=|vod=',
Array.map(Array.range(1, opponents), function(opponentIndex)
return INDENT .. '|opponent' .. opponentIndex .. '=' .. WikiCopyPaste.getOpponent(mode, showScore)
end),
Array.map(Array.range(1, bestof), function(mapIndex)
return INDENT .. '|map' .. mapIndex .. WikiCopyPaste._getMap(mode)
end),
'}}'
)

return table.concat(lines, '\n')
end

--subfunction used to generate code for the Map template, depending on the type of opponent
---@param mode string
---@return string
function WikiCopyPaste._getMap(mode)
local lines = Array.extend(
'={{Map',
INDENT .. INDENT .. '|map=|winner=',
INDENT .. INDENT .. '|o1p1={{Chars|}}|o2p1={{Chars|}}',
INDENT .. '}}'
)
return table.concat(lines, '\n')
end

return WikiCopyPaste
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
-- @Liquipedia
-- wiki=smash
-- page=Module:MatchGroup/Display/Bracket/Custom
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Array = require('Module:Array')
local Characters = require('Module:Characters')
local Class = require('Module:Class')
local Lua = require('Module:Lua')
local Table = require('Module:Table')

local OpponentLibraries = require('Module:OpponentLibraries')
local Opponent = OpponentLibraries.Opponent
local OpponentDisplay = OpponentLibraries.OpponentDisplay

local BracketDisplay = Lua.import('Module:MatchGroup/Display/Bracket')
local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')

local CustomBracketDisplay = {propTypes = {}}

---@param props {bracketId: string, config: BracketConfigOptions}
---@return Html
function CustomBracketDisplay.BracketContainer(props)
return BracketDisplay.Bracket({
bracket = MatchGroupUtil.fetchMatchGroup(props.bracketId) --[[@as MatchGroupUtilBracket]],
config = Table.merge(props.config, {
OpponentEntry = CustomBracketDisplay.OpponentEntry,
})
})
end

---@param props {opponent: SmashStandardOpponent, displayType: string, matchWidth: number}
---@return Html
function CustomBracketDisplay.OpponentEntry(props)
local opponentEntry = OpponentDisplay.BracketOpponentEntry(props.opponent)
if props.displayType == 'bracket' and props.opponent.type == Opponent.solo then
CustomBracketDisplay._addHeads(opponentEntry, props.opponent)
if props.opponent.placement == 1 then
opponentEntry.content:addClass('brkts-opponent-win')
end
elseif props.displayType == 'bracket' then
opponentEntry:addScores(props.opponent)
end
return opponentEntry.root
end

---@param opponentEntry BracketOpponentEntry
---@param opponent SmashStandardOpponent
function CustomBracketDisplay._addHeads(opponentEntry, opponent)
local game = opponent.players[1].game
local charactersNode = mw.html.create('div'):css('display', 'flex'):css('align-items', 'center')
Array.forEach(opponent.players[1].heads or {}, function(headData)
charactersNode:node(
mw.html.create('span')
:node(Characters.GetIconAndName{headData.name, game = game})
:css('opacity', headData.status == 0 and '0.3' or nil)
)
end)
opponentEntry.root:node(charactersNode)
end

return Class.export(CustomBracketDisplay)
Loading

0 comments on commit ea5e7b6

Please sign in to comment.