Skip to content
Open
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
61 changes: 61 additions & 0 deletions lua/wikis/leagueoflegends/TeamCard/Legacy/Custom.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
-- @Liquipedia
-- page=Module:TeamCard/Legacy/Custom
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Lua = require('Module:Lua')

local Array = Lua.import('Module:Array')
local InGameRoles = Lua.import('Module:InGameRoles', {loadData = true})
local LegacyTeamCard = Lua.import('Module:TeamCard/Legacy')
local Logic = Lua.import('Module:Logic')
local MathUtil = Lua.import('Module:MathUtil')
local Table = Lua.import('Module:Table')

local DEFAULT_MAX_PLAYER_INDEX = 10
local INGAME_ROLES_BY_ORDER = Table.map(InGameRoles, function (_, roleData)
return roleData.sortOrder, roleData.display
end)

local CustomLegacyTeamCard = {}

-- Template entry point
---@return Widget
function CustomLegacyTeamCard.run()
return LegacyTeamCard.run(CustomLegacyTeamCard)
end

---@param card table
---@return table
function CustomLegacyTeamCard.preprocessCard(card)
-- Add local template overrides
card.defaultRowNumber = MathUtil.toInteger(card.defaultRowNumber) or 5
card.t2title = Logic.emptyOr(card.t2title, 'Substitutes')
card.t3title = Logic.emptyOr(card.t3title, 'Staff')

-- Adjust position arguments and add default
Array.forEach(Array.range(1, DEFAULT_MAX_PLAYER_INDEX), function(index)
local key = 'p' .. index
card[key .. 'pos'] = Logic.emptyOr(
card[key .. 'pos'],
Table.extract(card, 'pos' .. index),
INGAME_ROLES_BY_ORDER[index]
)
end)

for tabIndex = 2, 3 do
Array.forEach(Array.range(1, DEFAULT_MAX_PLAYER_INDEX), function(index)
local key = 't' .. tabIndex .. 'p' .. index
card[key .. 'pos'] = Logic.emptyOr(
card[key .. 'pos'],
Table.extract(card, 't' .. tabIndex .. 'pos' .. index)
)
end)
end

return card
end

return CustomLegacyTeamCard
Loading