Skip to content
Closed
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
114 changes: 68 additions & 46 deletions lua/wikis/naraka/Infobox/Person/Player/Custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,41 @@

local Lua = require('Module:Lua')

local Array = Lua.import('Module:Array')
local CharacterIcon = Lua.import('Module:CharacterIcon')
local CharacterNames = Lua.import('Module:CharacterNames', {loadData = true})
local Class = Lua.import('Module:Class')
local Math = Lua.import('Module:MathUtil')
local String = Lua.import('Module:StringUtils')
local Table = Lua.import('Module:Table')
local TeamTemplate = Lua.import('Module:TeamTemplate')

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

-- Condition query dependencies
local Condition = Lua.import('Module:Condition')
local ConditionNode = Condition.Node
local Comparator = Condition.Comparator
local ColumnName = Condition.ColumnName
local ConditionUtil = Condition.Util

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

local SIZE_HERO = '25x25px'
local CURRENT_YEAR = tonumber(os.date('%Y'))

-- S-Tier tournament champion filter conditions
local S_TIER_CONDITIONS = {
ConditionUtil.noneOf(ColumnName('liquipediatiertype'), {'Showmatch', 'Qualifier'}),
ConditionNode(ColumnName('liquipediatier'), Comparator.eq, 1),
ConditionNode(ColumnName('placement'), Comparator.eq, 1),
}

-- A-Tier tournament champion filter conditions
local A_TIER_CONDITIONS = {
ConditionUtil.noneOf(ColumnName('liquipediatiertype'), {'Showmatch', 'Qualifier'}),
ConditionNode(ColumnName('liquipediatier'), Comparator.eq, 2),
ConditionNode(ColumnName('placement'), Comparator.eq, 1),
}

---@class NarakaInfoboxPlayer: Person
---@class NarakaInfoboxPlayer: InfoboxPerson

Check failure on line 44 in lua/wikis/naraka/Infobox/Person/Player/Custom.lua

View workflow job for this annotation

GitHub Actions / luals-code-style

Undefined class `InfoboxPerson`. (undefined-doc-class)
local CustomPlayer = Class.new(Player)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Testing

local CustomInjector = Class.new(Injector)

Expand All @@ -34,31 +51,58 @@
local player = CustomPlayer(frame)
player:setWidgetInjector(CustomInjector(player))

local args = player.args

-- Automatic achievements: display S-Tier and A-Tier separately
local sTierIcons = Achievements.player{
noTemplate = true,
baseConditions = S_TIER_CONDITIONS,
}
local aTierIcons = Achievements.player{
noTemplate = true,
baseConditions = A_TIER_CONDITIONS,
}
Comment on lines +56 to +64

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Tes


local achievementSections = {}

-- Tier label on left, icons keep centered
local function renderTierRow(label, icons)
return '<div style="position:relative;width:100%;;padding:6px 10px;box-sizing:border-box;text-align:center;">' ..
'<span style="position:absolute;left:10px;top:50%;transform:translateY(-50%);font-size:1.2em;font-weight:700;color:#000;white-space:nowrap;">' .. label .. '</span>' ..
'<span style="display:inline-block;">' .. icons .. '</span>' ..
'</div>'
end

if String.isNotEmpty(sTierIcons) then
table.insert(achievementSections, renderTierRow('S-Tier', sTierIcons))
end

if String.isNotEmpty(aTierIcons) then
table.insert(achievementSections, renderTierRow('A-Tier', aTierIcons))
end

args.achievements = table.concat(achievementSections, '')

-- Uppercase first letter in status
if args.status then
args.status = mw.getContentLanguage():ucfirst(args.status)
end

return player:createInfobox()
end

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

if id == 'custom' then
local heroIcons = Array.map(caller:getAllArgsForBase(args, 'hero'), function(hero, _)
return CharacterIcon.Icon{character = CharacterNames[hero:lower()], size = SIZE_HERO}
end)

return {
Cell{
name = #heroIcons > 1 and 'Signature Heroes' or 'Signature Hero',
children = {table.concat(heroIcons, '&nbsp;')},
}
}
elseif id == 'region' then
return {}
elseif id == 'history' then
table.insert(widgets, Cell{name = 'Retired', children = {args.retired}})
local currentYearEarnings = self.caller.earningsPerYear[CURRENT_YEAR] or 0
if currentYearEarnings == 0 then return widgets end
local currentYearEarningsDisplay = '$' .. mw.getContentLanguage():formatNum(Math.round(currentYearEarnings))

table.insert(widgets, Cell{name = 'Approx. Earnings '.. CURRENT_YEAR, children = {currentYearEarningsDisplay}})
end

return widgets
Expand All @@ -69,29 +113,7 @@
---@param personType string
---@return table
function CustomPlayer:adjustLPDB(lpdbData, args, personType)
for _, hero, heroIndex in Table.iter.pairsByPrefix(args, 'hero', {requireIndex = false}) do
lpdbData.extradata['signatureHero' .. heroIndex] = CharacterNames[hero:lower()]
end

if String.isNotEmpty(args.team2) then
lpdbData.extradata.team2 = TeamTemplate.getPageName(args.team2)
end

return lpdbData
end

---@return Widget?
function CustomPlayer:createBottomContent()
if not self:shouldStoreData(self.args) or String.isEmpty(self.args.team) then
return
end

local teamPage = TeamTemplate.getPageName(self.args.team)
if not teamPage then
return
end

return UpcomingTournaments.team{name = teamPage}
end

return CustomPlayer
Loading