Module:Region

From NBA 2K Esports Wiki
Jump to: navigation, search
To edit the documentation or categories for this module, click here.
local util_args = require('Module:ArgsUtil')
local LOOKUP = mw.loadData('Module:Regionnames')

local h = {}

function h.getInfo(str, settings)
	if not str then str = '' end
	settings.vars = util_args.lookupVars(str, LOOKUP)
	return
end

function h.makeImage(settings)
	local div = mw.html.create('div')
		:addClass('region-icon')
		:cssText(('color:#%s'):format(settings.vars.hex))
		:wikitext(settings.vars.short)
	return div
end

local p = {}

function p.main(frame)
	local args = util_args.merge(true)
	if not args[1] and not args.sub then
		return ''
	end
	local style = args[2] or 'rightlong'
	return p[style](args[1], args)
end

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

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

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

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

function p.onlyimage(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	return tostring(h.makeImage(settings))
end

function p.rightshort(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	local tbl = mw.html.create('div')
		:cssText('display:inline-block;')
	tbl:node(h.makeImage(settings))
	tbl:wikitext(' ' .. settings.vars.short)
	return tostring(tbl)
end

function p.rightmedium(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	local tbl = mw.html.create('div')
		:cssText('display:inline-block;')
	tbl:node(h.makeImage(settings))
	tbl:wikitext(' ' .. settings.vars.medium)
	return tostring(tbl) 
end

function p.rightlong(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	local tbl = mw.html.create('div')
		:cssText('display:inline-block;')
	tbl:node(h.makeImage(settings))
	tbl:wikitext(' ' .. settings.vars.long)
	return tostring(tbl) 
end

return p