More actions
Documentation for this module may be created at Module:Infobox GB 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 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 ['Math'] = {'GB homebrew applications', 'Maths Applications on GB', 'GB Homebrew Applications'}, ['Music Apps'] = {'GB homebrew applications', 'Music Applications on GB', 'GB Homebrew Applications'}, ['Music Disks'] = {'GB homebrew applications', 'Music Disks on GB', 'GB Homebrew Applications'}, ['Other Apps'] = {'GB homebrew applications', 'Other Applications on GB', 'GB Homebrew Applications'}, ['Test Roms'] = {'GB homebrew applications', 'Test Roms on GB', 'GB Homebrew Applications'}, ['Utilities'] = {'GB homebrew applications', 'Utility Applications on GB', 'GB Homebrew Applications'}, -- Games ['Action'] = {'GB homebrew games', 'Action Games on GB', 'GB Homebrew Games'}, ['Adventure'] = {'GB homebrew games', 'Adventure Games on GB', 'GB Homebrew Games'}, ['Arcade Games'] = {'GB homebrew games', 'Arcade Games on GB', 'GB Homebrew Games'}, ['Board'] = {'GB homebrew games', 'Board Games on GB', 'GB Homebrew Games'}, ['Card'] = {'GB homebrew games', 'Card Games on GB', 'GB Homebrew Games'}, ['Music'] = {'GB homebrew games', 'Music Games on GB', 'GB Homebrew Games'}, ['Other Games'] = {'GB homebrew games', 'Other Games on GB', 'GB Homebrew Games'}, ['Platform'] = {'GB homebrew games', 'Platform Games on GB', 'GB Homebrew Games'}, ['Puzzle'] = {'GB homebrew games', 'Puzzle Games on GB', 'GB Homebrew Games'}, ['Racing'] = {'GB homebrew games', 'Racing Games on GB', 'GB Homebrew Games'}, ['Role Playing'] = {'GB homebrew games', 'Role Playing Games on GB', 'GB Homebrew Games'}, ['Shooter'] = {'GB homebrew games', 'Shooter Games on GB', 'GB Homebrew Games'}, ['Simulation'] = {'GB homebrew games', 'Simulation Games on GB', 'GB Homebrew Games'}, ['Strategy'] = {'GB homebrew games', 'Strategy Games on GB', 'GB Homebrew Games'}, ['Trivia'] = {'GB homebrew games', 'Trivia Games on GB', 'GB Homebrew Games'}, -- Emulators ['Computer'] = {'GB homebrew emulators', 'Computer Emulators on GB', 'GB Homebrew Emulators'}, ['Console'] = {'GB homebrew emulators', 'Console Emulators on GB', 'GB Homebrew Emulators'}, ['Other Emulators'] = {'GB homebrew emulators', 'Other Emulators on GB', 'GB Homebrew Emulators'}, -- PC (PC Utilities for GB) ['Development'] = {'GB PC utilities', 'Development Utilities for GB', 'PC Utilities for GB'}, ['PC Utilities'] = {'GB PC utilities', 'Other PC Utilities for GB', 'PC Utilities for GB'}, -- Demos ['Demos'] = {'GB homebrew demos', 'Demo Applications on GB', 'GB Homebrew Demos'}, ['Game Demos'] = {'GB homebrew demos', 'Demo Games on GB', 'GB Homebrew Demos'}, ['Samples'] = {'GB homebrew demos', 'Code Samples on GB', 'GB Homebrew Demos'}, -- ROM Hack ['Game Hacks'] = {'all GB Rom Hacks', 'GB Game Hacks', 'GB Rom Hacks'}, ['Translations'] = {'all GB Rom Hacks', 'GB Game Translations', 'GB Rom Hacks'}, ['Hack Utilities'] = {'all GB Rom Hacks', 'GB Hack Utilities', 'GB Rom Hacks'}, } local category = categories[typeVal] if category then return string.format('[[List of %s#%s|%s]] [[Category:%s]] [[Category:%s]]', category[1], typeVal, typeVal, category[2], category[3]) 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 = { '3dsx', '3ds', '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:GB Open Source Homebrew]]' end return getLink( 'Source', source ) .. '[[Category:GB 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:3DS Homebrew in DownloadMii]]' else return "Version '''" .. dmversion .. "''' downloadable via [[DownloadMii]] [[Category:3DS 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, header2 = 'General', label3 = 'Author', data3 = a.author, label4 = 'Contributor', data4 = '', label5 = 'Ported by', data5 = '', label6 = 'Type', data6 = getType( a['type'] ), label7 = 'Version', data7 = a.version, label8 = 'License', data8 = getLicense( a.license ), label9 = 'Language', data9 = a.language, label10 = 'System', data10 = a.format, label11 = 'Last Updated', data11 = a.lastupdated, header13 = div3(), header20 = div(), header1 = 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.header11 = 'CIA information' ibData.label112 = 'Title ID' ibData.data112 = a.titleID or 'Unknown[[Category:3DS Homebrew missing CIA titleID]]' ibData.label113 = 'Unique ID' ibData.data113 = a.uniqueID or 'Unknown[[Category:3DS Homebrew missing CIA uniqueID]]' end return infobox.infobox( ibData ) end return p