More actions
Documentation for this module may be created at Module:Infobox Switch Homebrews/doc
local p = {} local function div() local div = mw.html.create( 'div' ) div :attr( 'id', 'Ads-Infobox' ) return tostring( div ) end local function div2() local div = mw.html.create( 'div' ) div :attr( 'id', 'largemobilebanner' ) return tostring( div ) end local function div3() local div = mw.html.create( 'div' ) div :attr( 'id', 'Ads-Infobox1' ) return tostring( div ) end local function div4() local div = mw.html.create( 'div' ) div :attr( 'id', 'Ads-Infobox3' ) return tostring( div ) end local function empty(param) return not param or param == '' end local function formatUser( user ) return '[[User:' .. user .. (user:find('|') and '' or ('|' .. user)) .. ']]' end local function userList( list ) if empty(list) then return end if not list:find(',') then return formatUser(list) end local ret = {} for user in mw.text.gsplit( list, '%s*,%s*' ) do ret[#ret+1] = formatUser(user) end return table.concat( ret, ', ' ) end local function getType(typeVal) if not typeVal then return end local categories = { -- Applications ['Media players'] = {'[[List of Switch Homebrew Applications]]', 'Switch Homebrew Media players'}, ['File Browsers'] = {'Applications', 'Switch Homebrew File Browsers'}, ['Save Tools'] = {'Applications', 'Switch Homebrew Save Tools'}, ['utility'] = {'utilities', 'Switch Homebrew utilities'}, ['operating system'] = {'operating systems', 'Switch Homebrew operating systems'}, ['math'] = {'math applications', 'Switch Homebrew math applications'}, ['other'] = {'other applications', 'Switch Homebrew other applications'}, -- Games ['Action'] = {'Action', 'Switch Homebrew Action games'}, ['arcade game'] = {'arcade games', 'Switch Homebrew arcade games'}, ['board game'] = {'board games', 'Switch Homebrew board games'}, ['card game'] = {'card games', 'Switch Homebrew card games'}, ['game engine'] = {'game engines', 'Switch Homebrew game engines'}, ['music game'] = {'music games', 'Switch Homebrew music games'}, ['platform game'] = {'platform games', 'Switch Homebrew platform games'}, ['puzzle game'] = {'puzzle games', 'Switch Homebrew puzzle games'}, ['racing game'] = {'racing games', 'Switch Homebrew racing games'}, ['role playing game'] = {'role playing games', 'Switch Homebrew role playing games'}, ['shooting game'] = {'shooting games', 'Switch Homebrew shooting games'}, ['simulation game'] = {'simulation games', 'Switch Homebrew simulation games'}, ['trivia game'] = {'trivia games', 'Switch Homebrew trivia games'}, ['other game'] = {'other games', 'Switch Homebrew other games'}, -- Emulators ['console emulator'] = {'console emulators', 'Switch Homebrew console emulators'}, ['handheld emulator'] = {'handheld emulators', 'Switch Homebrew handheld emulators'}, ['arcade emulator'] = {'arcade emulators', 'Switch Homebrew arcade emulators'}, ['computer emulator'] = {'computer emulators', 'Switch Homebrew computer emulators'}, -- Loaders ['loader'] = {'loaders', 'Switch Homebrew loaders'}, -- Exploits ['exploit'] = {'exploits', 'Switch Homebrew exploits'}, -- System Tools ['system tool'] = {'system tools', 'Switch Homebrew system tools'}, -- PC Utilities ['pc utility'] = {'PC utilities', 'Switch Homebrew PC utilities'}, -- Demos ['demo'] = {'demos', 'Switch Homebrew demos'}, } local category = categories[typeVal] if category then return string.format('[[Category:%s]] [[Category:Switch Homebrew %s]] Source included', category[1], category[2]) else return typeVal .. '[[Category:Infobox homebrew using invalid type parameter]]' end end local function getLicense( license ) if empty( license ) then return end local licenses = { ['Apache'] = '[https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0]', ['GNU GPL'] = '[https://www.gnu.org/licenses/gpl.html GNU GPL]', ['GNU LGPL'] = '[https://www.gnu.org/licenses/lgpl.html GNU LGPL]', ['BSD 2-Clause'] = '[http://opensource.org/licenses/BSD-2-Clause BSD 2-Clause]', ['BSD 3-Clause'] = '[http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause]', ['Mixed'] = 'Mixed', ['MIT'] = '[http://opensource.org/licenses/mit-license.html MIT License]', } return licenses[license] or license end local function getFormats( a ) local formats = { 'Switchx', 'Switch', 'cia', 'bin', 'dat', 'cxi' } local ret = {} for i=1,#formats do local f = formats[i] local tmp = a[f] if not empty(tmp) then local label = f == 'bin' and 'bin/elf' or f if tmp == 'yes' then ret[#ret+1] = label .. ' <span style="color:#00B000">✔</span>' elseif tmp == 'no' then ret[#ret+1] = label .. ' <span style="color:red">✘</span>' else ret[#ret+1] = label .. ' <span style="color:orange">?</span>' end end end if next(ret) == nil then return end -- We got nothing... return table.concat(ret, '<br />') end local function getLink( label, link, altlink ) if empty( link ) then return altlink end if link:find( '://' ) then return '[' .. link .. ' ' .. label .. ']' end return '[[' .. link .. '|' .. label .. ']]' end local function getSource( source ) if empty( source ) then return end if source == 'included' then return 'Source included[[Category:Switch open source homebrew]]' end return getLink( 'Source', source ) .. '[[Category:Switch open source homebrew]]' end local function getDonation( donation ) if empty( donation ) then return end if donation == 'included' then return 'Donation included[[Category:Support the author]]' end return getLink( 'Support Author', donation ) .. '[[Category:Support the author]]' end local function getDownloadMii( dm, dmversion, version ) if not dm or dm ~= 'yes' then return end if empty(dmversion) or dmversion == version then return 'Downloadable via [[DownloadMii]] [[Category:Switch Homebrew in DownloadMii]]' else return "Version '''" .. dmversion .. "''' downloadable via [[DownloadMii]] [[Category:Switch Homebrew in DownloadMii]]" end end function p.main( frame ) local a = frame:getParent().args local infobox = require( 'Module:Infobox' ) if not empty( a.title ) then frame:callParserFunction( 'DISPLAYTITLE', a.title ) end local ibData = { title = a.title, image = a.image, imagesize = a.imagesize or '48px', imagecaption = a.imagecaption, header3 = 'General', label4 = 'Author', data4 = a.author, label5 = 'Contributor', data5 = userList( a.contributor ), label6 = 'Ported by', data6 = userList( a.portedby ), label7 = 'Type', data7 = getType( a['type'] ), label8 = 'Version', data8 = a.version, label9 = 'License', data9 = getLicense( a.license ), label10 = 'Language', data10 = a.language, label11 = 'Format', data11 = getFormats( a ), label12 = 'Last Updated', data12 = a.lastupdated, header13 = div3(), header20 = div(), header2 = div2(), -- Links data15 = getLink( 'Download', a.download, a.downloadraw ), data16 = getLink( 'Website', a.website ), data17 = getSource( a.source ), data18 = getDonation( a.donation), data19 = getDownloadMii( a.dm, a.dmversion, a.version ), below = a.below } if ibData.data15 or ibData.data16 or ibData.data17 or ibData.data18 or ibData.data19 then ibData.header14 = 'Links' end if a.cia == 'yes' then ibData.header111 = 'CIA information' ibData.label112 = 'Title ID' ibData.data112 = a.titleID or 'Unknown[[Category:Switch Homebrew missing CIA titleID]]' ibData.label113 = 'Unique ID' ibData.data113 = a.uniqueID or 'Unknown[[Category:Switch Homebrew missing CIA uniqueID]]' end return infobox.infobox( ibData ) end return p