Skip to content
Draft
Show file tree
Hide file tree
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
58 changes: 58 additions & 0 deletions lua/wikis/commons/ControlsSettingsTable.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
-- @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 Class = Lua.import('Module:Class')
local Info = Lua.import('Module:Info')

local ControlsSettingsTableWidget = Lua.import('Module:Widget/ControlsSettingsTable')

local ControlsSettingsTable = Class.new()

---@param frame table
---@return Widget
function ControlsSettingsTable.create(frame)
local args = Arguments.getArgs(frame)
local config = Info.controlsSettingsTable or
error('You need to configure controlsSettingsTable in your wiki Module:Info')
local widget = ControlsSettingsTableWidget(config, args)
ControlsSettingsTable._saveToLpdb(config, args)
return widget:render()
end

---@private
---@param config {keys: string[], title: string}
---@param args {[string]: string?}
function ControlsSettingsTable._saveToLpdb(config, args)
local title = mw.title.getCurrentTitle().text
local extradata = ControlsSettingsTable._generateLpdbExtradata(config, args)
mw.ext.LiquipediaDB.lpdb_settings(title, {
name = 'movement',
reference = args.ref,
lastupdated = args.date,
gamesettings = mw.ext.LiquipediaDB.lpdb_create_json(extradata),
type = (args.controller or ''):lower()
})
end

---@private
---@param config {keys: string[], title: string}
---@param args {[string]: string?}
---@return {[string]: string?}
function ControlsSettingsTable._generateLpdbExtradata(config, args)
local lpdbData = {}
Array.forEach(config, function(item)
Array.forEach(item.keys, function(key)
lpdbData[key:lower()] = args[key:lower()]
end)
end)
return lpdbData
end

return ControlsSettingsTable
59 changes: 59 additions & 0 deletions lua/wikis/commons/Icon/ButtonTranslation.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
-- @Liquipedia
-- page=Module:Icon/ButtonTranslation
--
-- 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'
}
}
4 changes: 4 additions & 0 deletions lua/wikis/commons/Info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ return {
status = 2,
},
},
controlsSettingsTable = {
{keys = {'ability'}, title = 'Ability Name'},
{keys = {'ability_a', 'ability_b'}, title = 'Ability Name (a/b)'},
}
}
203 changes: 203 additions & 0 deletions lua/wikis/commons/Widget/ControlsSettingsTable.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
---
-- @Liquipedia
-- page=Module:Widget/ControlsSettingsTableWidget
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Lua = require('Module:Lua')

local Array = Lua.import('Module:Array')
local ButtonTranslation = Lua.import('Module:Icon/ButtonTranslation')
local Class = Lua.import('Module:Class')
local Date = Lua.import('Module:Date/Ext')
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')
local Widget = Lua.import('Module:Widget')

-- table2 aliases
local Row = TableWidgets.Row
local Cell = TableWidgets.Cell
local CellHeader = TableWidgets.CellHeader
local Table2 = TableWidgets.Table
local TableBody = TableWidgets.TableBody

---@class ControlsSettingsTableWidget: Widget
---@field config {keys: string[], title: string}
---@field args {[string]: string?}
local ControlsSettingsTableWidget = Class.new(Widget,
function(self, config, args)
self.config = config
self.args = args
end
)

---@return Widget
function ControlsSettingsTableWidget:render()
return Table2{
children = TableBody{children = self:_makeRows()},
title = self:_makeHeaderDisplay(),
footer = self:_makeWarningDisplay()
}
end

---@private
---@return Widget[]
function ControlsSettingsTableWidget:_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 ControlsSettingsTableWidget:_makeRow(configRow.title, buttons)
end)
end

---@private
---@param key string
---@return Widget?
function ControlsSettingsTableWidget:_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

---@private
---@param device string?
---@param button string?
---@return string
function ControlsSettingsTableWidget:_getImageName(device, button)
device = Logic.nilOr(device, ''):lower()
button = Logic.nilOr(button, ''):lower():gsub(' ', '_')
return ButtonTranslation[device][button] or 'ImageNotFound'
end

---@private
---@param imageName string
---@param button string
---@return Widget
function ControlsSettingsTableWidget:_makeButtonDisplay(imageName, button)
return Image{
imageLight = imageName,
size = 'md',
caption = button,
alt = button
}
end

---@private
---@return Widget
function ControlsSettingsTableWidget:_makeButtonStubIcon()
return IconFa{iconName = 'no', size = 'sm'}
end

---@private
---@param title string
---@param value Widget
---@return Widget
function ControlsSettingsTableWidget:_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

---@private
---@return Widget
function ControlsSettingsTableWidget:_makeHeaderDisplay()
return HtmlWidgets.Div{
css = {['text-align'] = 'center'},
children = {
'Control settings',
HtmlWidgets.Span{
children = self:_makeReferenceDisplay(),
css = {['margin-left'] = '10px'}
}
}
}
end

---@private
---@return Widget
function ControlsSettingsTableWidget:_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

---@private
---@return string|Widget
function ControlsSettingsTableWidget:_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

---@private
---@return Widget?
function ControlsSettingsTableWidget:_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

---@private
---@param text string
---@return Widget
function ControlsSettingsTableWidget:_makeWarning(text)
return {HtmlWidgets.Span{
classes = {'cinnabar-text'},
children = {HtmlWidgets.I{children = text}},
css = {['font-size'] = '90%'}
}}
end

return ControlsSettingsTableWidget
Loading