Difference between revisions of "Module:SNES button"
From ALttP Speedrunning Wiki
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
function p.main(frame) | function p.main(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
− | + | args[1] = args[1] or 'A' | |
− | return p._main( | + | return p._main(args) |
end | end | ||
− | function p._main( | + | function p._main(args) |
− | + | local ret = mw.html.create('span') | |
+ | :addClass('snes-button-wrapper') | ||
− | local | + | for _, v in ipairs(args) do |
+ | local b = mw.text.trim(v:lower()) | ||
− | + | if b:find('[+;,()/]') then | |
− | + | symbol(ret, b) | |
− | + | elseif b:find('[<>^vd]') then | |
− | + | dpad(ret, b) | |
+ | else | ||
+ | button(ret, b) | ||
+ | end | ||
end | end | ||
+ | |||
+ | ret:done() | ||
return tostring(ret) | return tostring(ret) | ||
end | end | ||
− | function | + | function symbol(parent, arg) |
− | local | + | local arg2 = mw.text.split(arg, '') |
+ | local ret = parent:tag('span') | ||
+ | ret:addClass('snes-button-delimiter') | ||
+ | :wikitext(arg2[1]) | ||
+ | :done() | ||
+ | end | ||
+ | |||
+ | function dpad(parent, arg) | ||
+ | local ret = parent:tag('span') | ||
ret:addClass('snes-button-dpad') | ret:addClass('snes-button-dpad') | ||
+ | |||
:tag('span') | :tag('span') | ||
:addClass('snes-button-dpad-vert') | :addClass('snes-button-dpad-vert') | ||
Line 170: | Line 48: | ||
:tag('span') | :tag('span') | ||
:addClass('snes-button-dpad-horz') | :addClass('snes-button-dpad-horz') | ||
+ | :done() | ||
+ | :tag('span') | ||
+ | :addClass('snes-button-dpad-mid') | ||
:done() | :done() | ||
:tag('span') | :tag('span') | ||
Line 177: | Line 58: | ||
:done() | :done() | ||
− | if arg:find('^') then | + | if arg:find('%^') then |
ret:addClass('snes-button-dpad-up') | ret:addClass('snes-button-dpad-up') | ||
end | end | ||
Line 193: | Line 74: | ||
end | end | ||
− | |||
end | end | ||
− | function button(arg) | + | function button(parent, arg) |
local buttonClass | local buttonClass | ||
Line 213: | Line 93: | ||
end | end | ||
− | local ret = | + | local ret = parent:tag('span') |
ret:addClass(buttonClass) | ret:addClass(buttonClass) | ||
:addClass(exactClass) | :addClass(exactClass) | ||
:wikitext(arg2) | :wikitext(arg2) | ||
+ | :done() | ||
− | |||
end | end | ||
return p | return p |
Latest revision as of 12:39, 20 July 2018
Documentation for this module may be created at button/doc&action=edit&redlink=1 Module:SNES button/doc
local p = {} function p.main(frame) local args = frame:getParent().args args[1] = args[1] or 'A' return p._main(args) end function p._main(args) local ret = mw.html.create('span') :addClass('snes-button-wrapper') for _, v in ipairs(args) do local b = mw.text.trim(v:lower()) if b:find('[+;,()/]') then symbol(ret, b) elseif b:find('[<>^vd]') then dpad(ret, b) else button(ret, b) end end ret:done() return tostring(ret) end function symbol(parent, arg) local arg2 = mw.text.split(arg, '') local ret = parent:tag('span') ret:addClass('snes-button-delimiter') :wikitext(arg2[1]) :done() end function dpad(parent, arg) local ret = parent:tag('span') ret:addClass('snes-button-dpad') :tag('span') :addClass('snes-button-dpad-vert') :done() :tag('span') :addClass('snes-button-dpad-horz') :done() :tag('span') :addClass('snes-button-dpad-mid') :done() :tag('span') :addClass('snes-button-dpad-templatearg') :wikitext(arg) :done() :done() if arg:find('%^') then ret:addClass('snes-button-dpad-up') end if arg:find('>') then ret:addClass('snes-button-dpad-right') end if arg:find('v') then ret:addClass('snes-button-dpad-down') end if arg:find('<') then ret:addClass('snes-button-dpad-left') end end function button(parent, arg) local buttonClass local arg2 = mw.text.split(arg, '') arg2[1] = arg2[1]:upper() arg2 = table.concat(arg2) local exactClass = 'snes-button-' .. arg2 if arg == 'a' or arg == 'b' or arg == 'x' or arg == 'y' then buttonClass = 'snes-button-face' elseif arg == 'l' or arg == 'r' then buttonClass = 'snes-button-bumper' elseif arg == 'start' or arg == 'select' then buttonClass = 'snes-button-mid' end local ret = parent:tag('span') ret:addClass(buttonClass) :addClass(exactClass) :wikitext(arg2) :done() end return p