Skip to content

Commit

Permalink
Merge branch 'main' into detailed-score
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Nov 4, 2024
2 parents 9b8f272 + 7040896 commit 2db6b98
Show file tree
Hide file tree
Showing 20 changed files with 228 additions and 296 deletions.
107 changes: 97 additions & 10 deletions components/infobox/commons/infobox_league.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ local TextSanitizer = Lua.import('Module:TextSanitizer')

local INVALID_TIER_WARNING = '${tierString} is not a known Liquipedia ${tierMode}'
local VENUE_DESCRIPTION = '<br><small><small>(${desc})</small></small>'
local STAY22_LINK = 'https://www.stay22.com/allez/roam?aid=liquipedia&campaign=infobox'..
'&address=${address}&checkin=${checkin}&checkout=${checkout}'

local Widgets = require('Module:Widget/All')
local Cell = Widgets.Cell
Expand All @@ -42,6 +44,8 @@ local Center = Widgets.Center
local Customizable = Widgets.Customizable
local Builder = Widgets.Builder
local Chronology = Widgets.Chronology
local Button = Lua.import('Module:Widget/Basic/Button')
local IconFa = Lua.import('Module:Widget/Image/Icon/Fontawesome')

---@class InfoboxLeague: BasicInfobox
local League = Class.new(BasicInfobox)
Expand Down Expand Up @@ -153,15 +157,9 @@ function League:createInfobox()
}}},
Builder{
builder = function()
local venues = {}
for prefix, venueName in Table.iter.pairsByPrefix(args, 'venue', {requireIndex = false}) do
local description
if String.isNotEmpty(args[prefix .. 'desc']) then
description = String.interpolate(VENUE_DESCRIPTION, {desc = args[prefix .. 'desc']})
end

table.insert(venues, self:createLink(venueName, args[prefix .. 'name'], args[prefix .. 'link'], description))
end
local venues = Array.map(League._parseVenues(args), function(venue)
return self:createLink(venue.id, venue.name, venue.link, venue.description)
end)

return {Cell{
name = 'Venue',
Expand Down Expand Up @@ -221,6 +219,78 @@ function League:createInfobox()
}
}
},
Builder{
builder = function()
local startDate, endDate = self.data.startDate, self.data.endDate
if not startDate or not endDate then
return
end
local onlineOrOffline = tostring(args.type or ''):lower()
if not onlineOrOffline:match('offline') then
return
end
local locations = Locale.formatLocations(args)
-- If more than one venue, don't show the accommodation section, as it is unclear which one the link is for
if locations.venue2 or locations.city2 then
return
end
-- Must have a venue or a city to show the accommodation section
if not locations.venue1 and not locations.city1 then
return
end

local addressParts = {}
table.insert(addressParts, locations.venue1)
table.insert(addressParts, locations.city1)
table.insert(addressParts, Flags.CountryName(locations.country1 or locations.region1))

-- Start date for the accommodation should be the day before the event, but at most 4 days before the event
-- End date for the accommodation should be 1 day after the event
local osdateEnd = DateExt.parseIsoDate(endDate)
osdateEnd.day = osdateEnd.day + 1
local osdateFictiveStart = DateExt.parseIsoDate(endDate)
osdateFictiveStart.day = osdateFictiveStart.day - 4
local osdateRealStart = DateExt.parseIsoDate(startDate)
osdateRealStart.day = osdateRealStart.day - 1

local osdateStart
if os.difftime(os.time(osdateFictiveStart), os.time(osdateRealStart)) > 0 then
osdateStart = osdateFictiveStart
else
osdateStart = osdateRealStart
end

local function buildStay22Link(address, checkin, checkout)
return String.interpolate(STAY22_LINK, {
address = address,
checkin = checkin,
checkout = checkout,
})
end

return {
Title{children = 'Accommodation'},
Center{children = {
Button{
linktype = 'external',
variant = 'primary',
size = 'md',
link = buildStay22Link(
table.concat(addressParts, ', '),
DateExt.toYmdInUtc(osdateStart),
DateExt.toYmdInUtc(osdateEnd)
),
children = {
IconFa{iconName = 'accommodation'},
' ',
'Find My Accommodation',
}
},
Center{children = 'Bookings earn Liquipedia a small commission.'}
}}
}
end
}
}

self.name = TextSanitizer.stripHTML(self.name)
Expand All @@ -235,7 +305,24 @@ function League:createInfobox()

return mw.html.create()
:node(self:build(widgets))
:node(Logic.readBool(args.autointro) and ('<br>' .. self:seoText(args)) or nil)
:node(Logic.readBool(args.autointro) and ('br>' .. self:seoText(args)) or nil)
end

---@param args table
---@return {id: string?, name: string?, link: string?, description: string?}[]
function League._parseVenues(args)
local venues = {}
for prefix, venueName in Table.iter.pairsByPrefix(args, 'venue', {requireIndex = false}) do
local name = args[prefix .. 'name']
local link = args[prefix .. 'link']
local description
if String.isNotEmpty(args[prefix .. 'desc']) then
description = String.interpolate(VENUE_DESCRIPTION, {desc = args[prefix .. 'desc']})
end

table.insert(venues, {id = venueName, name = name, link = link, description = description})
end
return venues
end

function League:_parseArgs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,21 @@ function CustomPlayer.run(frame)
player.args.history = automatedHistory
else
args.history = tostring(mw.html.create('div')
:addClass("show-when-logged-in")
:addClass("navigation-not-searchable")
:tag('big'):wikitext("Automated History"):done()
:wikitext(automatedHistory)
:tag('big'):wikitext("Manual History"):done())
.. args.history
:tag('div')
:tag('big')
:addClass("show-when-logged-in")
:addClass("navigation-not-searchable")
:wikitext("Automated History")
:done()
:wikitext(automatedHistory)
:done()
:tag('div')
:addClass("show-when-logged-in")
:addClass("navigation-not-searchable")
:tag('big'):wikitext("Manual History"):done()
:wikitext(args.history)
:done()
)
end

-- Automatic achievements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ function StarcraftMatchSummaryFfa._opponents(match)
-- Add match opponent data to game opponent and the other way around
Array.forEach(match.games, function (game, gameIndex)
game.extradata.opponents = Array.map(game.opponents, function (opponent, opponentIdx)
return {
return Table.merge(opponent, {
placement = opponent.placement,
status = game.extradata['status' .. opponentIdx] or 'S',
score = (game.scores or {})[opponentIdx],
}
})
end)
end)

Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/brawlhalla/match_legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function MatchLegacy._convertParameters(match2)
local opponentmatch2players = opponent.match2players or {}
if opponent.type == Opponent.solo then
local player = opponentmatch2players[1] or {}
match[prefix] = player.name:gsub(' ', '_')
match[prefix] = (player.name or ''):gsub(' ', '_')
match[prefix .. 'score'] = (tonumber(opponent.score) or 0) > 0 and opponent.score or 0
match[prefix .. 'flag'] = player.flag
match.extradata[prefix .. 'displayname'] = player.displayname
Expand Down
9 changes: 1 addition & 8 deletions components/match2/wikis/brawlhalla/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ local Operator = require('Module:Operator')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
local MatchSummary = Lua.import('Module:MatchSummary/Base')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
local WidgetUtil = Lua.import('Module:Widget/Util')

local OpponentLibraries = require('Module:OpponentLibraries')
Expand Down Expand Up @@ -56,19 +55,13 @@ function CustomMatchSummary._createGame(game)
local team1Characters = Array.map((game.opponents[1] or {}).players or {}, Operator.property('char'))
local team2Characters = Array.map((game.opponents[2] or {}).players or {}, Operator.property('char'))

local map = HtmlWidgets.Div{
children = DisplayHelper.MapAndStatus(game),
classes = {'brkts-popup-spaced'},
css = {['flex-grow'] = '1'}
}

return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
css = {['font-size'] = '80%', padding = '4px', ['min-height'] = '24px'},
children = WidgetUtil.collect(
MatchSummaryWidgets.Characters{characters = team1Characters, flipped = false},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
map,
MatchSummaryWidgets.GameCenter{children = DisplayHelper.MapAndStatus(game), css = {['flex-grow'] = 1}},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2},
MatchSummaryWidgets.Characters{characters = team2Characters, flipped = true}
)
Expand Down
104 changes: 21 additions & 83 deletions components/match2/wikis/brawlstars/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local DisplayHelper = require('Module:MatchGroup/Display/Helper')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local MapTypeIcon = require('Module:MapType')
local Operator = require('Module:Operator')
Expand All @@ -19,12 +18,6 @@ local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local MatchSummary = Lua.import('Module:MatchSummary/Base')
local WidgetUtil = Lua.import('Module:Widget/Util')

local GREEN_CHECK = '<i class="fa fa-check forest-green-text" style="width: 14px; text-align: center" ></i>'
local ICONS = {
check = GREEN_CHECK,
}
local NO_CHECK = '[[File:NoCheck.png|link=]]'

local CustomMatchSummary = {}

---@param args table
Expand All @@ -51,75 +44,36 @@ function CustomMatchSummary.createBody(match)
)}
end

---@param game MatchGroupUtilGame
---@param opponentIndex integer
---@return Html
function CustomMatchSummary._gameScore(game, opponentIndex)
local score = game.scores[opponentIndex]
local scoreDisplay = DisplayHelper.MapScore(score, opponentIndex, game.resultType, game.walkover, game.winner)
return mw.html.create('div'):wikitext(scoreDisplay)
end

---@param game MatchGroupUtilGame
---@return Html?
function CustomMatchSummary._createMapRow(game)
if not game.map then
return
end

local characterData = {
Array.map((game.opponents[1] or {}).players or {}, Operator.property('brawler')),
Array.map((game.opponents[2] or {}).players or {}, Operator.property('brawler')),
}

local row = MatchSummary.Row()

local centerNode = mw.html.create('div')
:addClass('brkts-popup-spaced')
:wikitext(CustomMatchSummary._getMapDisplay(game))
:css('text-align', 'center')

if game.resultType == 'np' then
centerNode:addClass('brkts-popup-spaced-map-skip')
end

local leftNode = mw.html.create('div')
:addClass('brkts-popup-spaced')
:node(MatchSummaryWidgets.Characters{
flipped = false,
characters = characterData[1],
bg = 'brkts-popup-side-color-blue', -- Team 1 is always blue
})
:node(CustomMatchSummary._createCheckMarkOrCross(game.winner == 1, 'check'))
:node(CustomMatchSummary._gameScore(game, 1))

local rightNode = mw.html.create('div')
:addClass('brkts-popup-spaced')
:node(CustomMatchSummary._gameScore(game, 2))
:node(CustomMatchSummary._createCheckMarkOrCross(game.winner == 2, 'check'))
:node(MatchSummaryWidgets.Characters{
flipped = true,
characters = characterData[2],
bg = 'brkts-popup-side-color-red', -- Team 2 is always red
})

row:addElement(leftNode)
:addElement(centerNode)
:addElement(rightNode)

row:addClass('brkts-popup-body-game')
:css('overflow', 'hidden')

-- Add Comment
if Logic.isNotEmpty(game.comment) then
row:addElement(MatchSummaryWidgets.Break{})
local comment = mw.html.create('div')
:wikitext(game.comment)
:css('margin', 'auto')
row:addElement(comment)
local function makeTeamSection(opponentIndex)
local characterData = Array.map((game.opponents[opponentIndex] or {}).players or {}, Operator.property('brawler'))
local teamColor = opponentIndex == 1 and 'blue' or 'red'
return {
MatchSummaryWidgets.Characters{
flipped = opponentIndex == 2,
characters = characterData,
bg = 'brkts-popup-side-color-' .. teamColor,
},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex},
DisplayHelper.MapScore(game.scores[opponentIndex], opponentIndex, game.resultType, game.walkover, game.winner)
}
end

return row:create()
return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
children = WidgetUtil.collect(
MatchSummaryWidgets.GameTeamWrapper{children = makeTeamSection(1)},
MatchSummaryWidgets.GameCenter{children = CustomMatchSummary._getMapDisplay(game)},
MatchSummaryWidgets.GameTeamWrapper{children = makeTeamSection(2), flipped = true},
MatchSummaryWidgets.GameComment{children = game.comment}
)
}
end

---@param game MatchGroupUtilGame
Expand All @@ -132,20 +86,4 @@ function CustomMatchSummary._getMapDisplay(game)
return mapDisplay
end

---@param showIcon boolean
---@param iconType string
---@return Html
function CustomMatchSummary._createCheckMarkOrCross(showIcon, iconType)
local container = mw.html.create('div')
container:addClass('brkts-popup-spaced'):css('line-height', '27px')

if showIcon then
container:node(ICONS[iconType])
else
container:node(NO_CHECK)
end

return container
end

return CustomMatchSummary
4 changes: 2 additions & 2 deletions components/match2/wikis/pokemon/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ function CustomMatchSummary.createBody(match)
)}
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@param date string
---@return MatchSummaryRow?
function CustomMatchSummary._createGame(game, gameIndex, date)
function CustomMatchSummary._createGame(date, game, gameIndex)
local extradata = game.extradata or {}

-- TODO: Change to use participant data
Expand Down
Loading

0 comments on commit 2db6b98

Please sign in to comment.