-
Notifications
You must be signed in to change notification settings - Fork 104
feat(infobox): Delta Force infobox league (WIP) #7276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
| local CustomInjector = Class.new(Injector) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing anno |
||
|
|
||
| local NONE_BREAKING_SPACE = ' ' | ||
| local DASH = '–' | ||
|
|
||
| local MODES = { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. categories should not be set as wiki text |
||
| 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 = { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. categories should not be set as wiki text |
||
| 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 '' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incomplete anno for this