Fortnite Esports Wiki
m (Aligning page content across wikis)
No edit summary
 
(20 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
local util_args = require('Module:ArgsUtil')
  +
local util_table = require('Module:TableUtil')
  +
local util_text = require('Module:TextUtil')
  +
local util_vars = require('Module:VarsUtil')
  +
local cache = require('mw.ext.LuaCache')
  +
local PREFIX = 'teamnames_09_'
  +
local SIZES = {
  +
short = 36,
  +
medium = 48,
  +
long = 60,
  +
square = 123
  +
}
  +
  +
local lang = mw.getLanguage('en')
  +
  +
local h = {}
 
local p = {}
 
local p = {}
   
function p.team ( frame )
+
function h.getInfo(str, settings)
  +
if str == '' or not str then str = 'tbd' end
local args = frame
 
  +
settings.vars = h.getFromVariableOrCache(str:gsub('_', ' '))
local text = ''
 
if frame == mw.getCurrentFrame() then
+
if settings.suffix then
  +
settings.link = settings.link or (settings.vars.link .. '/' .. settings.suffix)
args = require( 'Module:ProcessArgs' ).merge( true )
 
 
else
 
else
  +
settings.link = settings.link or settings.vars.link
frame = mw.getCurrentFrame()
 
 
end
 
end
  +
if settings.short then
  +
settings.vars.short = settings.short
  +
end
  +
settings.linked = not settings.vars.exception
  +
return
  +
end
   
  +
function h.getFromVariableOrCache(str)
local teaminput = mw.ustring.lower(args[1] or '')
 
local teamstyle = mw.ustring.lower(args[2] or 'default')
+
local key = PREFIX .. lang:lc(str)
  +
return util_vars.getObject(key) or h.getFromCacheOrTeamnames(str, key)
local size = args['size']
 
  +
end
 
local exceptionCases = mw.loadData( 'Module:Teamexceptions' )
 
 
--Empty
 
if not args[1] or args[1] == '' then
 
return ''
 
 
--Special Cases
 
elseif exceptionCases[teaminput] then
 
exception = exceptionCases[teaminput]
 
tstyles = mw.loadData( 'Module:Teamexceptionstyles' )
 
 
text = tstyles[teamstyle]
 
 
if not size then
 
text = text:gsub("REPLACESIZE","")
 
else
 
text = text:gsub("REPLACESIZE(%d+)px",size)
 
end
 
 
text = text:gsub("REPLACE(%u+)", { ["TEXT"] = exception["text"], ["SHORT"] = exception["text"], ["FILE"] = exception["image"], ["TITLE"] = exception["hover"] })
 
 
return text
 
 
-- Normal Teams
 
else
 
local tnames = mw.loadData( 'Module:Teamnames' )
 
local namevars = tnames[teaminput]
 
local logo = ""
 
   
  +
function h.getFromCacheOrTeamnames(str, key)
if not namevars then
 
  +
local vars = cache.get(key) or h.getFromTeamnames(str, key)
namevars = {link = args[1], long = args[1], medium = args[1], short = args['short'] or args[1] }
 
elseif type(namevars) == 'string' then
+
if vars.exists == nil then
  +
vars.exists = true
namevars = tnames[namevars]
 
  +
end
logo = namevars.link:gsub("+", " ")
 
  +
util_vars.setObject(key, vars)
else
 
  +
return vars
logo = namevars.link:gsub("+", " ")
 
end
+
end
 
local tstyles = mw.loadData('Module:Teamstyles')
 
 
text = tstyles[teamstyle]
 
 
if not size then
 
text = text:gsub("REPLACESIZE","")
 
else
 
text = text:gsub("REPLACESIZE(%d+)px",size)
 
end
 
 
text = text:gsub("REPLACE(%u+)", { ["LINK"] = namevars.link, ["LONG"] = namevars.long, ["MEDIUM"] = namevars.medium, ["SHORT"] = namevars.short, ["FILE"] = logo })
 
 
return text
 
   
  +
function h.getFromTeamnames(str, key)
  +
local vars_init = util_args.lookupVars(str, mw.loadData('Module:Teamnames'), true)
  +
local vars
  +
if vars_init then
  +
vars = util_table.shallowClone(vars_init)
  +
vars.file = vars.link or ''
  +
vars.exception = util_args.nilToFalse(vars.exception)
  +
vars.exists = true
  +
else
  +
vars = {
  +
link = str,
  +
long = str,
  +
medium = str,
  +
short = mw.ustring.upper(mw.ustring.sub(str:gsub('Team ',''), 1, 4)),
  +
file = '',
  +
exception = false,
  +
exists = false,
  +
}
  +
end
  +
cache.set(key, vars)
  +
return vars
  +
end
   
  +
function h.linkedDisplay(linked, link, display)
  +
if not linked then
  +
return display
 
end
 
end
  +
if (link or display) and (not link or not display) then
  +
error(('Incomplete Teamnames data for %s'):format(link or display))
  +
elseif not link or not display then
  +
error('Missing Teamnames data for a recent entry')
  +
end
  +
return ('[[%s|%s]]'):format(link, display)
 
end
 
end
  +
  +
function h.right(settings, size)
  +
return ('<span class="team"><span class="teamimage-right">%s</span><span class="teamname">%s</span></span>'):format(
  +
h.image(settings, size),
  +
settings.vars[size]
  +
)
  +
end
  +
  +
function h.rightlinked(settings, size)
  +
return ('<span class="team"><span class="teamimage-right">%s</span><span class="teamname">%s</span></span>'):format(
  +
h.image(settings, size),
  +
h.linkedDisplay(settings.linked, settings.link, settings.vars[size])
  +
)
  +
end
  +
  +
function h.left(settings, size)
  +
return ('<span class="team"><span class="teamname">%s</span><span class="teamimage-left">%s</span></span>'):format(
  +
settings.vars[size],
  +
h.image(settings, size)
  +
)
  +
end
  +
  +
function h.leftlinked(settings, size)
  +
return ('<span class="team"><span class="teamname">%s</span><span class="teamimage-left">%s</span></span>'):format(
  +
h.linkedDisplay(settings.linked, settings.link, settings.vars[size]),
  +
h.image(settings, size)
  +
)
  +
end
  +
  +
function h.image(settings, size, shape)
  +
return ('&#8288;[[File:%slogo %s.png|%spx|link=%s%s]]&#8288;'):format(
  +
settings.vars.file,
  +
shape or 'std',
  +
settings.size or SIZES[size],
  +
settings.linked and settings.link or '',
  +
settings.vars.class and ('|class=%s-logo-std'):format(settings.vars.class) or ''
  +
)
  +
end
  +
  +
function p.main(frame)
  +
-- this should NEVER be called from Lua, only invoked from MW
  +
local args = util_args.merge()
  +
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.linkifexists(str, settings)
  +
if not settings then settings = {} end
  +
h.getInfo(str, settings)
  +
if not settings.vars.exists then
  +
return nil
  +
end
  +
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)
  +
settings.linked = false
  +
return h.image(settings, 'long')
  +
end
  +
  +
function p.onlyimageshort(str, settings)
  +
if not settings then settings = {} end
  +
h.getInfo(str, settings)
  +
settings.linked = false
  +
return h.image(settings, 'short')
  +
end
  +
  +
function p.onlyimagelinked(str, settings)
  +
if not settings then settings = {} end
  +
h.getInfo(str, settings)
  +
return h.image(settings, 'long')
  +
end
  +
  +
function p.onlyimagelinkedmedium(str, settings)
  +
if not settings then settings = {} end
  +
h.getInfo(str, settings)
  +
return h.image(settings, 'medium')
  +
end
  +
  +
function p.onlyimagelinkedshort(str, settings)
  +
if not settings then settings = {} end
  +
h.getInfo(str, settings)
  +
return h.image(settings, 'short')
  +
end
  +
  +
function p.square(str, settings)
  +
if not settings then settings = {} end
  +
h.getInfo(str, settings)
  +
settings.linked = false
  +
return h.image(settings, 'square', 'square')
  +
end
  +
  +
function p.squarelinked(str, settings)
  +
if not settings then settings = {} end
  +
h.getInfo(str, settings)
  +
return h.image(settings, 'square', 'square')
  +
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
  +
 
return p
 
return p

Latest revision as of 21:43, 9 August 2021

Documentation for this module may be created at Module:Team/doc

local util_args = require('Module:ArgsUtil')
local util_table = require('Module:TableUtil')
local util_text = require('Module:TextUtil')
local util_vars = require('Module:VarsUtil')
local cache = require('mw.ext.LuaCache')
local PREFIX = 'teamnames_09_'
local SIZES = {
	short = 36,
	medium = 48,
	long = 60,
	square = 123
}

local lang = mw.getLanguage('en')

local h = {}
local p = {}

function h.getInfo(str, settings)
	if str == '' or not str then str = 'tbd' end
	settings.vars = h.getFromVariableOrCache(str:gsub('_', ' '))
	if settings.suffix then
		settings.link = settings.link or (settings.vars.link .. '/' .. settings.suffix)
	else
		settings.link = settings.link or settings.vars.link
	end
	if settings.short then
		settings.vars.short = settings.short
	end
	settings.linked = not settings.vars.exception
	return
end

function h.getFromVariableOrCache(str)
	local key = PREFIX .. lang:lc(str)
	return util_vars.getObject(key) or h.getFromCacheOrTeamnames(str, key)
end

function h.getFromCacheOrTeamnames(str, key)
	local vars = cache.get(key) or h.getFromTeamnames(str, key)
	if vars.exists == nil then
		vars.exists = true
	end
	util_vars.setObject(key, vars)
	return vars
end

function h.getFromTeamnames(str, key)
	local vars_init = util_args.lookupVars(str, mw.loadData('Module:Teamnames'), true)
	local vars
	if vars_init then
		vars = util_table.shallowClone(vars_init)
		vars.file = vars.link or ''
		vars.exception = util_args.nilToFalse(vars.exception)
		vars.exists = true
	else
		vars = {
			link = str,
			long = str,
			medium = str,
			short = mw.ustring.upper(mw.ustring.sub(str:gsub('Team ',''), 1, 4)),
			file = '',
			exception = false,
			exists = false,
		}
	end
	cache.set(key, vars)
	return vars
end

function h.linkedDisplay(linked, link, display)
	if not linked then
		return display
	end
	if (link or display) and (not link or not display) then
		error(('Incomplete Teamnames data for %s'):format(link or display))
	elseif not link or not display then
		error('Missing Teamnames data for a recent entry')
	end
	return ('[[%s|%s]]'):format(link, display)
end

function h.right(settings, size)
	return ('<span class="team"><span class="teamimage-right">%s</span><span class="teamname">%s</span></span>'):format(
		h.image(settings, size),
		settings.vars[size]
	)
end

function h.rightlinked(settings, size)
	return ('<span class="team"><span class="teamimage-right">%s</span><span class="teamname">%s</span></span>'):format(
		h.image(settings, size),
		h.linkedDisplay(settings.linked, settings.link, settings.vars[size])
	)
end

function h.left(settings, size)
	return ('<span class="team"><span class="teamname">%s</span><span class="teamimage-left">%s</span></span>'):format(
		settings.vars[size],
		h.image(settings, size)
	)
end

function h.leftlinked(settings, size)
	return ('<span class="team"><span class="teamname">%s</span><span class="teamimage-left">%s</span></span>'):format(
		h.linkedDisplay(settings.linked, settings.link, settings.vars[size]),
		h.image(settings, size)
	)
end

function h.image(settings, size, shape)
	return ('&#8288;[[File:%slogo %s.png|%spx|link=%s%s]]&#8288;'):format(
		settings.vars.file,
		shape or 'std',
		settings.size or SIZES[size],
		settings.linked and settings.link or '',
		settings.vars.class and ('|class=%s-logo-std'):format(settings.vars.class) or ''
	)
end

function p.main(frame)
	-- this should NEVER be called from Lua, only invoked from MW
	local args = util_args.merge()
	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.linkifexists(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	if not settings.vars.exists then
		return nil
	end
	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)
	settings.linked = false
	return h.image(settings, 'long')
end

function p.onlyimageshort(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	settings.linked = false
	return h.image(settings, 'short')
end

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

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

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

function p.square(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	settings.linked = false
	return h.image(settings, 'square', 'square')
end

function p.squarelinked(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	return h.image(settings, 'square', 'square')
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

return p