Difference between revisions of "Module:SNES button"

From ALttP Speedrunning Wiki
Jump to: navigation, search
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
  
p.CSS = [===[
+
function p.main(frame)
 +
local args = frame:getParent().args
  
{{#css:
+
args[1] = args[1] or 'A'
.snes-button,
 
.snes-button-face,
 
.snes-button-mid,
 
.snes-button-bumper {
 
display: inline-block;
 
text-align: center;
 
color: white;
 
border: 2px solid;
 
border-left: none;
 
border-top: none;
 
border-radius: 20px;
 
text-transform: capitalize;
 
}
 
  
.snes-button-face,
+
return p._main(args)
.snes-button-A,
+
end
.snes-button-B,
 
.snes-button-X,
 
.snes-button-Y {
 
width: 22px;
 
height: 22px;
 
font-weight: bold;
 
}
 
  
.snes-button-A {
+
function p._main(args)
background: #DA3948;
+
local ret = mw.html.create('span')
border-color: #610102;
+
:addClass('snes-button-wrapper')
}
 
  
.snes-button-B {
+
for _, v in ipairs(args) do
background: #FEBB52;
+
local b = mw.text.trim(v:lower())
border-color: #3E0A00;
 
}
 
  
.snes-button-X {
+
if b:find('[+;,()/]') then
background: #00489F;
+
symbol(ret, b)
border-color: #000A35;
+
elseif b:find('[<>^vd]') then
}
+
dpad(ret, b)
 
+
else
.snes-button-Y {
+
button(ret, b)
background: #00916A;
+
end
border-color: #00331B;
+
end
}
 
 
 
.snes-button-bumper {
 
width: 40px;
 
height: 16px;
 
padding-bottom: 2px;
 
font-weight: bold;
 
border-color: #8D8D8D;
 
background: #B8B8A8;
 
}
 
 
 
.snes-button-L {
 
border-radius: 15px 0 0 0;
 
}
 
 
 
.snes-button-R {
 
border-radius: 0 15px 0 0;
 
}
 
 
 
.snes-button-mid,
 
.snes-button-Start,
 
.snes-button-Select {
 
width: 60px;
 
height: 12px;
 
padding-bottom: 8px;
 
background: #4B545B;
 
border-color: #050704;
 
font-variant: small-caps;
 
}
 
 
 
 
 
.snes-button-dpad {
 
display: inline-block;
 
width: 42px;
 
height: 42px;
 
}
 
 
 
.snes-button-dpad-vert,
 
.snes-button-dpad-horz {
 
position: relative;
 
display: block;
 
background: #595E62;
 
border-radius: 3px;
 
border-style: solid;
 
border-width: 0;
 
border-color: #FF8080;
 
}
 
 
 
.snes-button-dpad-vert {
 
left: 14px;
 
width: 14px;
 
height: 42px;
 
min-height: 28px;
 
max-height: 42px;
 
}
 
 
 
.snes-button-dpad-up .snes-button-dpad-vert {
 
height: 28px;
 
border-top-width: 14px;
 
}
 
 
 
.snes-button-dpad-down .snes-button-dpad-vert {
 
height: 28px;
 
border-bottom-width: 14px;
 
}
 
 
 
.snes-button-dpad-up.snes-button-dpad-down .snes-button-dpad-vert {
 
height: 14px;
 
border-top-width: 14px;
 
}
 
 
 
.snes-button-dpad-horz {
 
bottom: 28px;
 
height: 14px;
 
min-width: 14px;
 
max-width: 42px;
 
}
 
 
 
.snes-button-dpad-left .snes-button-dpad-horz {
 
border-left-width: 14px;
 
}
 
 
 
.snes-button-dpad-right .snes-button-dpad-horz {
 
border-right-width: 14px;
 
}
 
 
 
.snes-button-dpad .snes-button-dpad-templatearg {
 
display: none;
 
}
 
 
 
}}
 
]===]
 
  
function p.main(frame)
+
ret:done()
local args = frame:getParent().args
 
  
local b = args[1]
+
return tostring(ret)
return p._main(b)
 
 
end
 
end
  
function p._main(b)
+
function symbol(parent, arg)
b = mw.text.trim(b:lower())
+
local arg2 = mw.text.split(arg, '')
 
+
local ret = parent:tag('span')
if b:find('[<>^v]') then
+
ret:addClass('snes-button-delimiter')
return dpad(b)
+
:wikitext(arg2[1])
else
+
:done()
return button(b)
 
end
 
 
end
 
end
  
function dpad(arg)
+
function dpad(parent, arg)
local ret = mw.html.create('span')
+
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 165: 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 172: 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 188: Line 74:
 
end
 
end
  
return ret
 
 
end
 
end
  
function button(arg)
+
function button(parent, arg)
 
local buttonClass
 
local buttonClass
  
Line 200: Line 85:
 
local exactClass = 'snes-button-' .. arg2
 
local exactClass = 'snes-button-' .. arg2
  
if arg == 'a' or arg == 'b' or arg == 'c' or arg == 'd' then
+
if arg == 'a' or arg == 'b' or arg == 'x' or arg == 'y' then
 
buttonClass = 'snes-button-face'
 
buttonClass = 'snes-button-face'
 
elseif arg == 'l' or arg == 'r' then
 
elseif arg == 'l' or arg == 'r' then
Line 208: Line 93:
 
end
 
end
 
 
local ret = mw.html.create('span')
+
local ret = parent:tag('span')
  
 
ret:addClass(buttonClass)
 
ret:addClass(buttonClass)
 
:addClass(exactClass)
 
:addClass(exactClass)
 
:wikitext(arg2)
 
:wikitext(arg2)
 +
:done()
  
return ret
 
 
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