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
100 changes: 100 additions & 0 deletions lua/wikis/rematch/Infobox/Person/Player/Custom.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
-- @Liquipedia
-- page=Module:Infobox/Person/Player/Custom
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Lua = require('Module:Lua')
local Array = Lua.import('Module:Array')
local Class = Lua.import('Module:Class')
local Flags = Lua.import('Module:Flags')
local Namespace = Lua.import('Module:Namespace')
local String = Lua.import('Module:StringUtils')

local Injector = Lua.import('Module:Widget/Injector')
local Player = Lua.import('Module:Infobox/Person')

local PlayerAchievements = Lua.import('Module:Infobox/Extension/Achievements')

local Widgets = Lua.import('Module:Widget/All')
local Cell = Widgets.Cell

---@class RematchInfoboxPlayer: Person
local CustomPlayer = Class.new(Player)
---@class RematchInfoboxPlayerWidgetInjector: WidgetInjector
---@field caller RematchInfoboxPlayer
local CustomInjector = Class.new(Injector)

---@param frame Frame
---@return Html
function CustomPlayer.run(frame)
local player = CustomPlayer(frame)
player:setWidgetInjector(CustomInjector(player))

player.args.autoTeam = true
player.args.achievements = PlayerAchievements.player{}

return player:createInfobox()
end

---@param id string
---@param widgets Widget[]
---@return Widget[]
function CustomInjector:parse(id, widgets)
local caller = self.caller
local args = caller.args

if id == 'status' then
local positions = Array.parseCommaSeparatedString(args.positions, ',')
local validPositions = Array.map(positions, String.nilIfEmpty)
local label = #validPositions > 1 and 'Positions' or 'Position'
return {
Cell{name = label, content = Array.map(validPositions, function(pos)
local capitalizedPos = String.upperCaseFirst(pos)
return '[[:Category:' .. capitalizedPos .. 's|' .. capitalizedPos .. ']]'
end)}
}
end
return widgets
end

---@param args table
---@param birthDisplay string
---@param personType string
---@param status PlayerStatus
---@return string[]
function CustomPlayer:getCategories(args, birthDisplay, personType, status)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as already mentioned before
do not overwrite the commons function!
if you actually need to append the list of categories with wiki specific ones use CustomPlayer:getWikiCategories(categories) instead!

if not Namespace.isMain() then return {} end

local categories = {}
local roles = String.isNotEmpty(args.roles) and Array.parseCommaSeparatedString(args.roles, ',') or {}

Array.forEach(roles, function(role)
local roleCategory = role .. 's'
table.insert(categories, roleCategory)
end)

Array.forEach(self:getLocations(), function(country)
local demonym = Flags.getLocalisation(country)
if demonym then
Array.forEach(roles, function(role)
local roleCategory = demonym .. ' ' .. role .. 's'
table.insert(categories, roleCategory)
end)
end
end)

if String.isNotEmpty(args.positions) then
local positions = Array.parseCommaSeparatedString(args.positions, ',')
local validPositions = Array.map(positions, String.nilIfEmpty)
Array.forEach(validPositions, function(pos)
local category = String.upperCaseFirst(pos) .. 's'
table.insert(categories, category)
end)
end

return categories
end

return CustomPlayer
Loading