Module:Button

--	This module compares and outputs a button depending on the game or system	you've specified. --

local b = {} local result = {} --	instead of typing the system over and over, these sys- variables have	the name of the system, so it avoids typos and needing to change the	comparisons manually.	to make this consistent, for each new system prefix the variable with	'sys-' (e.g 'local sysDonkeyKongStation = 'DK Station') -- local sysWiiU = 'Wii U' local sysSwitch = 'Switch'

function gameToConsole(game) --		this function returns a console depending on what you set on the 'game'		argument. On the original template, the system and 'game' parameters were		pretty much the same, so the list needs also to include the console name		as well.		As mentioned in the b.main later, the inputs from the template are		automatically made lowercase, trimmed, and removes special characters		(such as dashes), so just make the keys like 'cometobrazil' or 'donkeykong'.		don't forget the comma at the end of each item! It's like a basic JSON.	-- local c = {} c = { ['wiiu'] = sysWiiU, ['s'] = sysWiiU, ['s1'] = sysWiiU, ['splatoon'] = sysWiiU, ['splatoon1'] = sysWiiU, ['switch'] = sysSwitch, ['s2'] = sysSwitch, ['splatoon2'] = sysSwitch, ['s3'] = sysSwitch, ['splatoon3'] = sysSwitch, ['octoexpansion'] = sysSwitch, ['oe'] = sysSwitch, ['splatoon 1'] = 'dummytest2', ['dummy'] = 'dummy', }	-- just a fallback if no argument is passed to 'game' if not c[game] then return c[sysWiiU] else return c[game] end end

function buttonOutput(system, button, frame) --		this function creates a nested comparison list. So if system, which has		passed through gameToConsole already (see on b.main ), will check		each "parent" list with the 'system' argument, then the "children" lists,		with the 'button' argument. The 'frame' argument is just to pass the		frames from b.main to this function.		In fact, to avoid visual bloat, you could move this function to a subpage,		something like Module:Button/Output, because eventually this list will		grow more and more I imagine.	-- local o = {} --		personally I would recommend the staff to adapt the Wii U buttons to		the Switch style (icons through CSS rather than images) to keep consistency.		The Switch's handheld icon uses an image instead of an icon, and doing		a whole if-else checking just for that would be quite annoying. Moving		the Wii U icons to the Switch style you're doing could remove the if-else		statement at the bottom as well.		and as mentioned later in the b.main, the button and system input from		the template/module is automatically trimmed and lowercase. Don't worry		about dashes or anything else.	-- o = { [sysWiiU] = { ['a'] = '', ['b'] = '', ['dpad'] = '', ['gamepad'] = '', ['home'] = '', ['l'] = '', ['leftstick'] = '', ['ls'] = '', ['minus'] = '', ['plus'] = '', ['r'] = '', ['rightstick'] = '', ['rs'] = '', ['x'] = '', ['y'] = '', ['z'] = frame:preprocess(''), ['zl'] = '', ['zl1'] = frame:preprocess(''), ['zr'] = '', ['zr1'] = frame:preprocess(''), },		[sysSwitch] = { ['a'] = {class = 'switch-icon a', title = 'A'}, ['b'] = {class = 'switch-icon b', title = 'B'}, ['capture'] = {class = 'switch-icon capture', title = 'Capture'}, ['controlleroutline'] = {class = 'switch-icon controller-outline', title = 'Pro'}, ['dpad'] = {class = 'pro-icon d-pad', title = 'D-Pad'}, ['dpaddown'] = {class = 'pro-icon d-pad-down', title = 'D-Pad Down'}, ['dpadleft'] = {class = 'pro-icon d-pad-left', title = 'D-Pad Left'}, ['dpadright'] = {class = 'pro-icon d-pad-right', title = 'D-Pad Right'}, ['dpadup'] = {class = 'pro-icon d-pad-up', title = 'D-Pad Up'}, ['gyropitch'] = {class = 'pro-icon gyro-pitch', title = 'Gyro Pitch'}, ['gyroroll'] = {class = 'pro-icon gyro-roll', title = 'Gyro Roll'}, ['gyroyaw'] = {class = 'pro-icon gyro-yaw', title = 'Gyro Yaw'}, -- handheld uses an image, please change it to an icon like the others. ['home'] = {class = 'switch-icon home', title = 'Home'}, ['l'] = {class = 'switch-icon l', title = 'L'}, ['leftstickall'] = {class = 'switch-icon left-stick-all', title = 'Left Stick All'}, ['leftstickclick'] = {class = 'switch-icon left-stick-click', title = 'Left Stick Click'}, ['leftstickdown'] = {class = 'switch-icon left-stick-down', title = 'Left Stick Down'}, ['leftstickleftright'] = {class = 'switch-icon left-stick-left-right', title = 'Left Stick Left-Right'}, ['leftstickleft'] = {class = 'switch-icon left-stick-left', title = 'Left Stick Left'}, ['leftstickright'] = {class = 'switch-icon left-stick-right', title = 'Left Stick Right'}, ['leftstickupdown'] = {class = 'switch-icon left-stick-up-down', title = 'Left Stick Up-Down'}, ['leftstickup'] = {class = 'switch-icon left-stick-up', title = 'Left Stick Up'}, ['leftstick'] = {class = 'switch-icon left-stick', title = 'Left Stick'}, ['ls'] = {class = 'switch-icon left-stick', title = 'Left Stick'}, ['minus'] = {class = 'switch-icon minus', title = 'Minus'}, ['plus'] = {class = 'switch-icon plus', title = 'Plus'}, ['pro'] = {class = 'pro-icon controller-outline', title = 'Pro'}, ['r'] = {class = 'switch-icon r', title = 'R'}, ['rightstickall'] = {class = 'switch-icon right-stick-all', title = 'Right Stick All'}, ['rightstickclick'] = {class = 'switch-icon right-stick-click', title = 'Right Stick Click'}, ['rightstickdown'] = {class = 'switch-icon right-stick-down', title = 'Right Stick Down'}, ['rightstickleftright'] = {class = 'switch-icon right-stick-left-right', title = 'Right Stick Left-Right'}, ['rightstickleft'] = {class = 'switch-icon right-stick-left', title = 'Right Stick Left'}, ['rightstickright'] = {class = 'switch-icon right-stick-right', title = 'Right Stick Right'}, ['rightstickupdown'] = {class = 'switch-icon right-stick-up-down', title = 'Right Stick Up-Down'}, ['rightstickup'] = {class = 'switch-icon right-stick-up', title = 'Right Stick Up'}, ['rightstick'] = {class = 'switch-icon right-stick', title = 'Right Stick'}, ['rs'] = {class = 'switch-icon right-stick', title = 'Right Stick'}, ['sl'] = {class = 'switch-icon sl', title = 'SL'}, ['sr'] = {class = 'switch-icon sr', title = 'SR'}, ['x'] = {class = 'switch-icon x', title = 'X'}, ['y'] = {class = 'switch-icon y', title = 'Y'}, ['zl'] = {class = 'switch-icon zl', title = 'ZL'}, ['zr'] = {class = 'switch-icon zr', title = 'ZR'}, },	}	local panel if system ~= sysWiiU then panel = ' ' return panel else return o[system][button] end end

function b.main(frame) -- the button input from the template local input = frame:getParent.args[1] or 'a'	-- Wii U set as the default system local game = frame:getParent.args['game'] or frame:getParent.args[2] or sysWiiU -- removing whitespace and special characters from 'input' and 'game' input = mw.ustring.lower(mw.ustring.gsub(input, '[%p%c%s]', '')) game = gameToConsole(mw.ustring.lower(mw.ustring.gsub(game, '[%p%c%s]', ''))) table.insert(result, buttonOutput(game, input, frame)) return table.concat(result, '') end

return b