Skip to content

Commit

Permalink
handle rounds midway through better
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Jan 17, 2025
1 parent 73f16f3 commit fc60481
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions components/widget/standings/widget_standings_ffa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ function StandingsFfaWidget:render()

---@type StandingsModel
local standings = self.props.standings
local roundCount = #standings.rounds
local lastFinishedRound = (Array.maxBy(
Array.filter(standings.rounds, function(round) return round.finished end),
function (round) return round.round end
) or {round = 0}).round

return DataTable{
wrapperClasses = {'standings-ffa', 'toggle-area', 'toggle-area-' .. roundCount},
wrapperClasses = {'standings-ffa', 'toggle-area', 'toggle-area-' .. lastFinishedRound},
classes = {'wikitable-bordered', 'wikitable-striped'},
attributes = {
['data-toggle-area'] = roundCount,
},
attributes = {['data-toggle-area'] = lastFinishedRound},
children = WidgetUtil.collect(
-- Outer header
HtmlWidgets.Tr{children = HtmlWidgets.Th{
Expand All @@ -52,12 +53,12 @@ function StandingsFfaWidget:render()
css = {['position'] = 'relative'},
children = {
HtmlWidgets.Span{
children = standings.section
children = standings.title
},
HtmlWidgets.Span{
css = {['position'] = 'absolute', ['left'] = '0', ['top'] = '-6px'},
children = RoundSelector{
rounds = roundCount,
rounds = lastFinishedRound,
hasEnded = standings.rounds[#standings.rounds].finished,
}
},
Expand All @@ -77,6 +78,9 @@ function StandingsFfaWidget:render()
)},
-- Rows
Array.flatMap(standings.rounds, function(round)
if round.round > lastFinishedRound then
return {}
end
return Array.map(round.opponents, function(slot)
local positionBackground = slot.positionStatus and ('bg-' .. slot.positionStatus) or nil
local teamBackground = slot.definitiveStatus and ('bg-' .. slot.definitiveStatus) or nil
Expand Down
2 changes: 1 addition & 1 deletion standard/array.lua
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ end
---@param array T[]
---@param funct fun(item: T): V
---@param compare? fun(maxScore: V, score: V): boolean
---@return V
---@return T
---@nodiscard
function Array.maxBy(array, funct, compare)
compare = compare or Array.lexicalCompareIfTable
Expand Down

0 comments on commit fc60481

Please sign in to comment.