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

local Lua = require('Module:Lua')

local Class = Lua.import('Module:Class')
local PageLink = Lua.import('Module:Page')
local String = Lua.import('Module:StringUtils')

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

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

---@class DeltaforceLeagueInfobox: InfoboxLeague
local CustomLeague = Class.new(League)
Copy link
Collaborator

Choose a reason for hiding this comment

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

incomplete anno for this

local CustomInjector = Class.new(Injector)
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing anno


local NONE_BREAKING_SPACE = ' '
local DASH = '–'

local MODES = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

categories should not be set as wiki text
handle them in the intended function instead

warfare = 'Warfare[[Category:Warfare Mode Tournaments]]',
operations = 'Operations[[Category:Operations Mode Tournaments]]',
default = '[[Category:Unknown Mode Tournaments]]',
}
MODES.wf = MODES.warfare
MODES.op= MODES.operations

local PLATFORMS = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

categories should not be set as wiki text
handle them in the intended function instead

pc = 'PC[[Category:PC Competitions]]',
mobile = 'Mobile[[Category:Mobile Competitions]]',
console = 'Console[[Category:Console Competitions]]',
crossplay = 'Cross-platform[[Category:Cross-platform Competitions]]',
default = '[[Category:Unknown Platform Competitions]]',
}

---@param frame Frame
---@return Widget
function CustomLeague.run(frame)
local league = CustomLeague(frame)
league:setWidgetInjector(CustomInjector(league))

return league:createInfobox()
end

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

if id == 'gamesettings' then
return {
Cell{name = 'Game mode', children = {self.caller:_getGameMode(args)}},
Cell{name = 'Patch', children = {CustomLeague._getPatchVersion(args)}},
Cell{name = 'Platform', children = {self.caller:_getPlatform(args)}},
}
elseif id == 'customcontent' then
Copy link
Collaborator

Choose a reason for hiding this comment

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

use Array.append or WidgetUtil.collect

if args.player_number then
table.insert(widgets, Title{children = 'Players'})
table.insert(widgets, Cell{name = 'Number of players', children = {args.player_number}})
end

--teams section
if args.team_number then
table.insert(widgets, Title{children = 'Teams'})
table.insert(widgets, Cell{name = 'Number of teams', children = {args.team_number}})
end
end
return widgets
end

---@param lpdbData table
---@param args table
---@return table
function CustomLeague:addToLpdb(lpdbData, args)
lpdbData.extradata.individual = String.isNotEmpty(args.player_number) and 'true' or ''
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this needed?


return lpdbData
end

---@param args table
---@return string?
function CustomLeague:_getGameMode(args)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why return nil on empty but default on bullshit inputs?

should not return a build link but instead just the plain text and then use the according option in the cell this is used in
(this would also allow using this when building the categories)

if String.isEmpty(args.mode) then
return nil
end

local mode = MODES[string.lower(args.mode or '')] or MODES['default']

return mode
end

---@param args table
---@return string?
function CustomLeague:_getPlatform(args)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

if String.isEmpty(args.platform) then
return nil
end

return PLATFORMS[string.lower(args.platform)] or PLATFORMS.default
end

---@param args table
---@return string?
function CustomLeague._getPatchVersion(args)
Copy link
Collaborator

Choose a reason for hiding this comment

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

use widgets together with WidgetUtil.collect

if String.isEmpty(args.patch) then return nil end
local content = PageLink.makeInternalLink(args.patch, 'Patch ' .. args.patch)
if String.isNotEmpty(args.epatch) then
return content .. NONE_BREAKING_SPACE .. DASH .. NONE_BREAKING_SPACE
.. PageLink.makeInternalLink(args.epatch, 'Patch ' .. args.epatch)
end

return content
end

return CustomLeague
Loading