Module:Team

local util_args = require('Module:ArgsUtil') local LOOKUP = mw.loadData('Module:Teamnames') local SIZES = { short = 38, medium = 45, long = 60, square = 123 }

local h = {}

function h.getInfo(str, settings) if str == '' or not str then str = 'tbd' end settings.vars = util_args.lookupVars(str, LOOKUP, true) if settings.vars then settings.file = settings.vars.link else settings.vars = { link = str, long = str, medium = str } if settings.short then settings.vars.short = settings.short else -- if we don't have actual variables defined for this team then -- other than 'Team ', the shortname will be the first 4 characters of the long name settings.vars.short = mw.ustring.upper(mw.ustring.sub(str:gsub('Team ',''), 1, 4)) end settings.file = '' end if settings.suffix then settings.link = settings.vars.link .. '/' .. settings.suffix else settings.link = settings.vars.link end settings.linked = not settings.vars.exception return end

function h.linkedDisplay(linked, link, display) if not linked then return display else return ('%s'):format(link, display) end end

function h.right(settings, size) return ('  %s  '):format(		settings.file,		settings.size or SIZES[size],		settings.linked and settings.link or '',		settings.vars[size]	) end

function h.rightlinked(settings, size) return ('  %s  '):format(		settings.file,		settings.size or SIZES[size],		settings.linked and settings.link or '',		h.linkedDisplay(settings.linked, settings.link, settings.vars[size])	) end

function h.left(settings, size) return (' %s   '):format(		settings.vars[size],		settings.file,		settings.size or SIZES[size],		settings.linked and settings.link or ''	) end

function h.leftlinked(settings, size) return (' %s   '):format(		h.linkedDisplay(settings.linked, settings.link, settings.vars[size]),		settings.file,		settings.size or SIZES[size],		settings.linked and settings.link or ''	) end

local p = {} function p.main(frame) -- this should NEVER be called from Lua, only invoked from MW	local args = util_args.merge(true) if not args[1] then return '' end local style = args[2] or 'rightlonglinked' args.size = args.size and args.size:gsub('px','') return p[style](args[1], args) end

function p.teamlinkname(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return settings.link end

function p.teammediumname(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return settings.vars.medium end

function p.teamname(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return settings.vars.long end

function p.short(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return settings.vars.short end

function p.onlyimage(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return (''):format(		settings.file,		settings.size or SIZES.long,		settings.link	) end

function p.onlyimagelinked(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return ():format(		settings.file,		settings.size or SIZES.long,		settings.linked and settings.link or 	) end

function p.onlyimagelinkedshort(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return ():format(		settings.file,		settings.size or SIZES.short,		settings.linked and settings.link or 	) end

function p.square(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return (''):format(		settings.file,		settings.size or SIZES.square,		settings.title or settings.link	) end

function p.squarelinked(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return ():format(		settings.file,		settings.size or SIZES.square,		settings.linked and settings.link or 	) end

function p.mediumplainlinked(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.linkedDisplay(settings.linked, settings.link, settings.vars.medium) end

function p.plainlinked(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.linkedDisplay(settings.linked, settings.link, settings.vars.long) end

function p.rightshort(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.right(settings, 'short') end

function p.rightmedium(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.right(settings, 'medium') end

function p.rightlong(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.right(settings, 'long') end

function p.rightshortlinked(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.rightlinked(settings, 'short') end

function p.rightmediumlinked(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.rightlinked(settings, 'medium') end

function p.rightlonglinked(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.rightlinked(settings, 'long') end

function p.leftshort(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.left(settings, 'short') end

function p.leftmedium(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.left(settings, 'medium') end

function p.leftlong(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.left(settings, 'long') end

function p.leftshortlinked(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.leftlinked(settings, 'short') end

function p.leftmediumlinked(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.leftlinked(settings, 'medium') end

function p.leftlonglinked(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return h.leftlinked(settings, 'long') end

function p.table(str, settings) return settings.vars end

function p.team ( frame ) local args = frame if frame == mw.getCurrentFrame then args = require( 'Module:ProcessArgs' ).merge( true ) else frame = mw.getCurrentFrame end local teaminput = mw.ustring.lower(args[1] or '') local teamstyle = mw.ustring.lower(args[2] or 'rightlonglinked') local exceptionCases = mw.loadData('Module:Teamexceptions') --Empty if not args[1] or args[1] == '' then return '' --Special Cases elseif exceptionCases[teaminput] then namevars = exceptionCases[teaminput] Styles = require('Module:Teamexceptionstyles') settings = Styles.styleNames(teamstyle) if args['size'] then settings.size = args['size'] end return Styles[settings.style](namevars, settings) -- Normal Teams else local tnames = mw.loadData('Module:Teamnames') local Styles = require('Module:Teamstyles') local namevars = tnames[teaminput] local settings = { size = args['size'] }

if not namevars then namevars = { link = args[1], long = args[1], medium = args[1], short = args['short'] or args[1] } settings.logo = "" elseif type(namevars) == 'string' then namevars = tnames[namevars] end return Styles[teamstyle](namevars, settings) end end return p