Fall Guys: Ultimate Knockout Wiki
Advertisement

require('Module:No globals')
local checkType = require('libraryUtil').checkType
--local inspect = require('Module:Inspect').inspect
local newBuffer = require('Module:OutputBuffer')

local p = {}

local function _new(page, pageAnchor, displayName, icon, iconInlineSize)
	checkType('_new', 1, page, 'string', false)
	checkType('_new', 2, pageAnchor, 'string', true)
	checkType('_new', 3, displayName, 'string', false)
	checkType('_new', 4, icon, 'string', false)
	checkType('_new', 5, iconInlineSize, 'string', false)
	return {
		page = page,
		pageAnchor = pageAnchor,
		displayName = displayName,
		icon = icon,
		iconInlineSize = iconInlineSize,
	}
end

function p.getCurrencies()
	return {
		fame = _new('Fame', nil, 'Fame', 'UI currency fame 1080p.png', '20px'),
		kudos = _new('Kudos', nil, 'Kudos', 'UI currency kudos 1080p.png', '22px'),
		crowns = _new('Crowns', nil, 'Crowns', 'UI currency crowns 1080p.png', '20px'),
		crown_shards = _new('Crown Shards', nil, 'Crown Shards', 'UI currency shards 1080p.png', '16px'),
		show_bucks = _new('Show-Bucks', nil, 'Show-Bucks', 'UI currency show bucks 1080p.png', '22px'),
		tokens = _new('Tokens', nil, 'Tokens', 'ui-icon-generic-token.png', '24px'),
		tokens_clank = _new('Tokens', 'Clank', 'Clank Tokens', 'ui-icon-clank-token.png', '24px'),
		tokens_ratchet = _new('Tokens', 'Ratchet', 'Ratchet Tokens', 'ui-icon-ratchet-token.png', '24px'),
		tokens_louie = _new('Tokens', 'Louie', 'Louie Tokens', 'ui-icon-louie-token.png', '24px'),
		tokens_mooncake = _new('Tokens', 'Mooncake', 'Mooncake Tokens', 'ui-icon-mooncake-token.png', '24px'),
		tokens_pumpkin = _new('Tokens', 'Pumpkin', 'Pumpkin Tokens', 'ui-icon-halloween-token.png', '24px'),
		tokens_sackboy = _new('Tokens', 'Sackboy', 'Sackboy Tokens', 'ui-icon-sackboy-token.png', '24px'),
		tokens_focus = _new('Tokens', 'Focus', 'Focus Tokens', 'ui-icon-focus-token.png', '24px'),
		tokens_jack = _new('Tokens', 'Jack', 'Jack Tokens', 'ui-icon-jack-token.png', '24px'),
		tokens_dumbbell = _new('Tokens', 'Dumbbell', 'Dumbbell Tokens', 'ui-icon-dumbbell-token.png', '24px'),
		tokens_heart = _new('Tokens', 'Heart', 'Heart Tokens', 'ui-icon-weekofromance-token.png', '24px'),
		tokens_sweet = _new('Tokens', 'Sweet', 'Sweet Tokens', 'ui-icon-sweet-token.png', '24px'),
		tokens_star = _new('Tokens', 'Star', 'Star Tokens', 'ui-icon-star-token.png', '24px'),
	}
end

local function _buildIcon(currencies, currencyId, iconSize, noLink, alignment)
	checkType('_buildIcon', 1, currencies, 'table', false)
	
	local currency = currencies[currencyId]
	if type(currency) ~= "table" then
		error('invalid currencyId')
	end
	
	local getBuffer, print, printf = newBuffer()
	
	printf('File:%s', currency.icon)
	if iconSize then
		print(iconSize)
	end
	if alignment then
		print(alignment)
	end
	if not noLink then
		if currency.pageAnchor then
			printf('link=%s#%s', currency.page, currency.pageAnchor)
		else
			printf('link=%s', currency.page)
		end
	end
	
	return '[['..getBuffer('|')..']]'
end

function p.buildIcon(currencyId, iconSize, noLink, alignment)
	checkType('buildIcon', 1, currencyId, 'string', false)
	checkType('buildIcon', 2, iconSize, 'string', true)
	checkType('buildIcon', 3, noLink, 'boolean', true)
	checkType('buildIcon', 4, alignment, 'string', true)
	return _buildIcon(p.getCurrencies(), currencyId, iconSize, noLink, alignment)
end

function p.buildAmount(currencyId, amount)
	checkType('buildAmount', 1, currencyId, 'string', false)
	checkType('buildAmount', 2, amount, 'number', false)
	
	local currencies = p.getCurrencies()
	
	local currency = currencies[currencyId]
	if type(currency) ~= "table" then
		error('invalid currencyId')
	end
	
	local iconElement = mw.html.create('span')
		:addClass('icon')
        :wikitext(_buildIcon(currencies, currencyId, currency.iconInlineSize, false, 'text-bottom'))
        
	local amountElement = mw.html.create('span')
		:addClass('amount')
        :wikitext(amount)
	
	return mw.html.create('span')
		:addClass('currency-amount')
		:css('display', 'inline-block')
        :wikitext(tostring(iconElement))
        :wikitext(' ')
        :wikitext(tostring(amountElement))
end

function p.buildLink(currencyId, noIcon)
	checkType('buildLink', 1, currencyId, 'string', false)
	checkType('buildLink', 2, noIcon, 'boolean', true)
	
	local currencies = p.getCurrencies()
	
	local currency = currencies[currencyId]
	if type(currency) ~= "table" then
		error('invalid currencyId')
	end
	
	local link
	if currency.pageAnchor then
		link = mw.ustring.format('[[%s#%s|%s]]', currency.page, currency.pageAnchor, currency.displayName)
	else
		link = mw.ustring.format('[[%s|%s]]', currency.page, currency.displayName)
	end
	
	local iconElement = mw.html.create('span')
		:addClass('icon')
        :wikitext(_buildIcon(currencies, currencyId, currency.iconInlineSize, false, 'text-bottom'))
        
	local linkElement = mw.html.create('span')
		:addClass('link')
        :wikitext(link)
	
	local rootElement = mw.html.create('span')
		:addClass('currency-link')
		:css('display', 'inline-block')
	
	if not noIcon then
		rootElement = rootElement
	        :wikitext(tostring(iconElement))
	        :wikitext(' ')
	end
	
	return rootElement
		:wikitext(tostring(linkElement))
end

return p
Advertisement