Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lua/wikis/commons/Widget/Standings/Ffa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ local function StandingsFfa(props)
function (round) return round.round end
) or {round = 0}).round

local entryByRound = Array.map(standings.rounds, function(round)
local byName = {}
Array.forEach(round.opponents, function(entry)
byName[Opponent.toName(entry.opponent)] = entry
end)
return byName
end)
Comment on lines +46 to +52

local standingsTable = TableWidgets.Table{
classes = {'standings-ffa'},
columns = WidgetUtil.collect(
Expand All @@ -64,7 +72,7 @@ local function StandingsFfa(props)
if round.round > activeRounds then
return
end
return Helpers._createRoundBody(standings, round)
return Helpers._createRoundBody(standings, round, entryByRound)
end)
),
striped = false
Expand Down Expand Up @@ -146,9 +154,11 @@ end
---@private
---@param standings StandingsModel
---@param round StandingsRound
---@param entryByRound table[]
---@return Renderable
function Helpers._createRoundBody(standings, round)
function Helpers._createRoundBody(standings, round, entryByRound)
return TableWidgets.TableBody{children = Array.map(round.opponents, function (slot)
local slotName = Opponent.toName(slot.opponent)
return TableWidgets.Row{
attributes = {
['data-position-status'] = slot.positionStatus,
Expand Down Expand Up @@ -180,12 +190,10 @@ function Helpers._createRoundBody(standings, round)
children = slot.tiebreakerValues[tiebreaker.id] and slot.tiebreakerValues[tiebreaker.id].display or ''
}
end),
Helpers._showRoundColumns(standings) and Array.map(standings.rounds, function (columnRound)
Helpers._showRoundColumns(standings) and Array.map(standings.rounds, function (columnRound, columnIndex)
local text
if columnRound.round <= round.round then
local opponent = Array.find(columnRound.opponents, function(columnSlot)
return Opponent.same(columnSlot.opponent, slot.opponent)
end)
local opponent = entryByRound[columnIndex][slotName]
if opponent then
local roundStatus = opponent.specialStatus
if roundStatus == '' then
Expand Down
20 changes: 14 additions & 6 deletions lua/wikis/commons/Widget/Standings/Swiss.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ local function StandingsSwiss(props)

local lastRound = standings.rounds[#standings.rounds]

local entryByRound = Array.map(standings.rounds, function(round)
local byName = {}
Array.forEach(round.opponents, function(entry)
byName[Opponent.toName(entry.opponent)] = entry
end)
return byName
end)
Comment on lines +34 to +40

return TableWidgets.Table{
classes = {'standings-swiss'},
title = Logic.nilIfEmpty(standings.title),
Expand All @@ -40,7 +48,7 @@ local function StandingsSwiss(props)
Helpers.headerRow(standings),
-- Rows
TableWidgets.TableBody{children = Array.map(lastRound.opponents, function(slot)
return Helpers.createRow(standings, slot)
return Helpers.createRow(standings, slot, entryByRound)
end)}
),
striped = false
Expand Down Expand Up @@ -94,8 +102,10 @@ end
---@private
---@param standings StandingsModel
---@param slot StandingsEntryModel
---@param entryByRound table[]
---@return Renderable
function Helpers.createRow(standings, slot)
function Helpers.createRow(standings, slot, entryByRound)
local slotName = Opponent.toName(slot.opponent)
return TableWidgets.Row{
attributes = {['data-position-status'] = slot.positionStatus},
children = WidgetUtil.collect(
Expand Down Expand Up @@ -123,10 +133,8 @@ function Helpers.createRow(standings, slot)
children = slot.tiebreakerValues[tiebreaker.id] and slot.tiebreakerValues[tiebreaker.id].display or ''
}
end),
Array.map(standings.rounds, function(columnRound)
local entry = Array.find(columnRound.opponents, function(columnSlot)
return Opponent.same(columnSlot.opponent, slot.opponent)
end)
Array.map(standings.rounds, function(columnRound, columnIndex)
local entry = entryByRound[columnIndex][slotName]
if not entry then
return TableWidgets.Cell{}
end
Expand Down
Loading