-
Notifications
You must be signed in to change notification settings - Fork 104
feat: ControlsSettingsTable module #7264
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
Draft
SobakaPirat
wants to merge
5
commits into
Liquipedia:main
Choose a base branch
from
SobakaPirat:ControlsSettingsTable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| --- | ||
| -- @Liquipedia | ||
| -- page=Module:ControlsSettingsTable | ||
| -- | ||
| -- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
| -- | ||
| local Lua = require('Module:Lua') | ||
|
|
||
| local Arguments = Lua.import('Module:Arguments') | ||
| local Array = Lua.import('Module:Array') | ||
| local ButtonTranslation = Lua.import('Module:Links/ButtonTranslation') | ||
| local Class = Lua.import('Module:Class') | ||
| local Date = Lua.import('Module:Date/Ext') | ||
| local Info = Lua.import('Module:Info') | ||
| local Logic = Lua.import('Module:Logic') | ||
| local String = Lua.import('Module:StringUtils') | ||
|
|
||
| local HtmlWidgets = Lua.import('Module:Widget/Html/All') | ||
| local Dialog = Lua.import('Module:Widget/Basic/Dialog') | ||
| local IconFa = Lua.import('Module:Widget/Image/Icon/Fontawesome') | ||
| local Image = Lua.import('Module:Widget/Image/Icon/Image') | ||
| local TableWidgets = Lua.import('Module:Widget/Table2/All') | ||
|
|
||
| -- table2 aliases | ||
| local Row = TableWidgets.Row | ||
| local Cell = TableWidgets.Cell | ||
| local CellHeader = TableWidgets.CellHeader | ||
| local Table2 = TableWidgets.Table | ||
| local TableBody = TableWidgets.TableBody | ||
|
|
||
| ---@class ControlsSettingsTable | ||
| ---@field config {keys: string[], title: string}[] | ||
| ---@field args {[string]: string?} | ||
| local ControlsSettingsTable = Class.new( | ||
| function(self, args, config) | ||
| self.args = args | ||
| self.config = config | ||
| end | ||
| ) | ||
|
|
||
| ---@param frame table | ||
| ---@return Widget | ||
| function ControlsSettingsTable.create(frame) | ||
| local args = Arguments.getArgs(frame) | ||
| local config = Info.controlsSettingsTable | ||
| local controlsSettingsTable = ControlsSettingsTable(args, config) | ||
| controlsSettingsTable:saveToLpdb() | ||
| return controlsSettingsTable:render() | ||
| end | ||
|
|
||
| function ControlsSettingsTable:saveToLpdb() | ||
| local title = mw.title.getCurrentTitle().text | ||
| local extradata = self:generateLpdbExtradata() | ||
| mw.ext.LiquipediaDB.lpdb_settings(title, { | ||
| name = 'movement', | ||
| reference = self.args.ref, | ||
| lastupdated = self.args.date, | ||
| gamesettings = mw.ext.LiquipediaDB.lpdb_create_json(extradata), | ||
| type = (self.args.controller or ''):lower(), | ||
| }) | ||
| end | ||
|
|
||
| ---@return {[string]: string?} | ||
| function ControlsSettingsTable:generateLpdbExtradata() | ||
| local lpdbData = {} | ||
| Array.forEach(self.config, function(item) | ||
| Array.forEach(item.keys, function(key) | ||
| lpdbData[key:lower()] = self.args[key:lower()] | ||
| end) | ||
| end) | ||
| return lpdbData | ||
| end | ||
|
|
||
| ---@return Widget | ||
| function ControlsSettingsTable:render() | ||
| return Table2{ | ||
| children = TableBody{children = self:makeRows()}, | ||
| title = self:makeHeaderDisplay(), | ||
| footer = self:makeWarningDisplay(), | ||
| } | ||
| end | ||
|
|
||
| ---@return Widget[] | ||
| function ControlsSettingsTable:makeRows() | ||
| local nonEmptyRows = Array.filter(self.config, function(configRow) | ||
| return Array.any(configRow.keys, function(key) | ||
| return String.isNotEmpty(self.args[key:lower()]) | ||
| end) | ||
| end) | ||
| return Array.map(nonEmptyRows, function(configRow) | ||
| local buttons = Array.map(configRow.keys, function(key) | ||
| return self:makeButtonIcon(key) or self:makeButtonStubIcon() | ||
| end) | ||
| return ControlsSettingsTable:makeRow(configRow.title, buttons) | ||
| end) | ||
| end | ||
|
|
||
| ---@param key string | ||
| ---@return Widget? | ||
| function ControlsSettingsTable:makeButtonIcon(key) | ||
| local button = self.args[key:lower()] | ||
| if String.isEmpty(button) then | ||
| return nil | ||
| end | ||
| ---@cast button string | ||
| if self.args.controller and self.args.controller:lower() == 'kbm' then | ||
| return HtmlWidgets.Kbd{children = button} | ||
| end | ||
| local imageName = self:getImageName(self.args.controller, button) | ||
| return self:makeButtonDisplay(imageName, button) | ||
| end | ||
|
|
||
| ---@param device string? | ||
| ---@param button string? | ||
| ---@return string | ||
| function ControlsSettingsTable:getImageName(device, button) | ||
| device = Logic.nilOr(device, ''):lower() | ||
| button = Logic.nilOr(button, ''):lower():gsub(' ', '_') | ||
| return ButtonTranslation[device][button] or 'ImageNotFound' | ||
| end | ||
|
|
||
| ---@param imageName string | ||
| ---@param button string | ||
| ---@return Widget | ||
| function ControlsSettingsTable:makeButtonDisplay(imageName, button) | ||
| return Image{ | ||
| imageLight = imageName, | ||
| size = 'md', | ||
| caption = button, | ||
| alt = button, | ||
| } | ||
| end | ||
|
|
||
| ---@return Widget | ||
| function ControlsSettingsTable:makeButtonStubIcon() | ||
| return IconFa{iconName = 'no', size = 'sm'} | ||
| end | ||
|
|
||
| ---@param title string | ||
| ---@param value Widget | ||
| ---@return Widget | ||
| function ControlsSettingsTable:makeRow(title, value) | ||
| return Row{ | ||
| children = { | ||
| CellHeader{children = title, align = 'right'}, | ||
| Cell{ | ||
| children = HtmlWidgets.Div{ | ||
| children = value, | ||
| css = {display = 'flex', gap = '6px', ['align-items'] = 'center'} | ||
| }, | ||
| align = 'left' | ||
| } | ||
| } | ||
| } | ||
| end | ||
|
|
||
| ---@return Widget | ||
| function ControlsSettingsTable:makeHeaderDisplay() | ||
| return HtmlWidgets.Div{ | ||
| css = {['text-align'] = 'center'}, | ||
| children = { | ||
| 'Control settings', | ||
| HtmlWidgets.Span{ | ||
| children = self:makeReferenceDisplay(), | ||
| css = {['margin-left'] = '10px'} | ||
| } | ||
| } | ||
| } | ||
| end | ||
|
|
||
| ---@return Widget | ||
| function ControlsSettingsTable:makeReferenceDisplay() | ||
| local timestamp = Date.readTimestamp(self.args.date) | ||
| local date = timestamp and Date.formatTimestamp('M j, Y', timestamp) or '?' | ||
| return Dialog{ | ||
| trigger = IconFa{ | ||
| iconName = 'reference', | ||
| size = 'sm', | ||
| }, | ||
| title = 'Reference', | ||
| children = HtmlWidgets.Div{ | ||
| children = { | ||
| self:makeReferenceSource(), | ||
| HtmlWidgets.Br{}, | ||
| HtmlWidgets.I{ | ||
| children = 'Last updated on ' .. date | ||
| } | ||
| } | ||
| } | ||
| } | ||
| end | ||
|
|
||
| ---@return string|Widget | ||
| function ControlsSettingsTable:makeReferenceSource() | ||
| local args = self.args | ||
| if args.ref and args.ref:lower():gsub(' ', '') == 'insidesource' then | ||
| return HtmlWidgets.Abbr{ | ||
| children = 'Inside source', | ||
| attributes = {title = 'Liquipedia has gained this information from a trusted inside source'} | ||
| } | ||
| end | ||
| return Logic.nilOr(self.args.ref, '?') | ||
| end | ||
|
|
||
| ---@return Widget? | ||
| function ControlsSettingsTable:makeWarningDisplay() | ||
| if Logic.isEmpty(self.args.ref) then | ||
| return self:makeWarning('No reference specified!') | ||
| elseif Logic.isEmpty(self.args.date) then | ||
| return self:makeWarning('No date of last update specified!') | ||
| end | ||
| return nil | ||
| end | ||
|
|
||
| ---@param text string | ||
| ---@return Widget | ||
| function ControlsSettingsTable:makeWarning(text) | ||
| return {HtmlWidgets.Span{ | ||
| classes = {'cinnabar-text'}, | ||
| children = {HtmlWidgets.I{children = text}}, | ||
| css = {['font-size'] = '90%'} | ||
| }} | ||
| end | ||
|
|
||
| return ControlsSettingsTable | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| --- | ||
| -- @Liquipedia | ||
| -- page=Module:Links/ButtonTranslation | ||
|
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. i don't get why this is under Links |
||
| -- | ||
| -- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
| -- | ||
|
|
||
| return { | ||
| playstation = { | ||
| cross = 'PlayStation_button_X.svg', | ||
| triangle = 'PlayStation_button_T.svg', | ||
| circle = 'PlayStation_button_C.svg', | ||
| square = 'PlayStation_button_S.svg', | ||
| l1 = 'PlayStation_button_L1.svg', | ||
| l2 = 'PlayStation_button_L2.svg', | ||
| l3 = 'PlayStation_button_L3.svg', | ||
| r1 = 'PlayStation_button_R1.svg', | ||
| r2 = 'PlayStation_button_R2.svg', | ||
| r3 = 'PlayStation_button_R3.svg', | ||
| left_stick = 'PlayStation_button_analog_L.svg', | ||
| right_stick = 'PlayStation_button_analog_R.svg', | ||
| arrow_up = 'Gamepad_button_arrow_up.svg', | ||
| arrow_down = 'Gamepad_button_arrow_down.svg', | ||
| arrow_left = 'Gamepad_button_arrow_left.svg', | ||
| arrow_right = 'Gamepad_button_arrow_right.svg' | ||
| }, | ||
| xbox = { | ||
| a = 'Xbox_button_A.svg', | ||
| y = 'Xbox_button_Y.svg', | ||
| b = 'Xbox_button_B.svg', | ||
| x = 'Xbox_button_X.svg', | ||
| lb = 'Xbox_Left_Bumper.svg', | ||
| lt = 'Xbox_Left_Trigger.svg', | ||
| rb = 'Xbox_Right_Bumper.svg', | ||
| rt = 'Xbox_Right_Trigger.svg', | ||
| left_stick = 'Xbox_Left_stick.svg', | ||
| right_stick = 'Xbox_Right_stick.svg', | ||
| arrow_up = 'Gamepad_button_arrow_up.svg', | ||
| arrow_down = 'Gamepad_button_arrow_down.svg', | ||
| arrow_left = 'Gamepad_button_arrow_left.svg', | ||
| arrow_right = 'Gamepad_button_arrow_right.svg' | ||
| }, | ||
| switch = { | ||
| a = 'Switch_pro_button_A.svg', | ||
| y = 'Switch_pro_button_Y.svg', | ||
| b = 'Switch_pro_button_B.svg', | ||
| x = 'Switch_pro_button_X.svg', | ||
| l = 'Switch_pro_button_L.svg', | ||
| zl = 'Switch_pro_button_ZL.svg', | ||
| r = 'Switch_pro_button_R.svg', | ||
| zr = 'Switch_pro_button_ZR.svg', | ||
| left_stick = 'PlayStation_button_analog_L.svg', | ||
| right_stick = 'PlayStation_button_analog_R.svg', | ||
| arrow_up = 'Gamepad_button_arrow_up.svg', | ||
| arrow_down = 'Gamepad_button_arrow_down.svg', | ||
| arrow_left = 'Gamepad_button_arrow_left.svg', | ||
| arrow_right = 'Gamepad_button_arrow_right.svg' | ||
| }, | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this is not defined...