Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:CosmeticInfo

From MCC Island Wiki

This module is invoked by Template:Cosmetic to greatly simplify creating pages for cosmetics, using info gathered from the API and stored in the data page.


local getArgs = require('Module:Arguments').getArgs

local cosmeticData = mw.loadData('Module:CosmeticInfo/Data')
if not cosmeticData then
	return "Error: Unable to load data"
end

local p = {}

function p.getDescription(frame)
	local glyphs = {
		["<glyph:\"mcc:icon.tooltips.veteran\"> "] = "<br />[[File:Icon-Veteran.png|16px]] <span style=\"color: #52C8FF; font-weight: bold\">",
		["<glyph:\"mcc:icon.tooltips.squidtek\"> "] = "<br />[[File:Icon-Squidtek.png|16px]] <span style=\"color: #52C8FF; font-weight: bold\">",
		["<glyph:\"mcc:icon.info_blue\"> "] = "<br />[[File:Icon-Info-Blue.png|16px]] <span style=\"color: #55FF55; font-weight: bold\">",
	}
	local args = getArgs(frame)
	local description = cosmeticData["cosmetics"][args.name]["description"]
	
	local openSpan = false
	for key, val in pairs(glyphs) do
		if string.find(description, key) then
			if openSpan == false then
				description = description:gsub(key, "</span>" .. val)
			else
				description = description:gsub(key, val)
			end
			openSpan = true
		end
	end
	
	if openSpan then
		description = description .. "</span>"
	end
	
	return description
end

function p.getType(frame)
	local args = getArgs(frame)
	return cosmeticData["cosmetics"][args.name]["type"]
end

function p.getCollection(frame)
	local args = getArgs(frame)
	return cosmeticData["cosmetics"][args.name]["collection"]
end

function p.getRarity(frame)
	local args = getArgs(frame)
	return cosmeticData["cosmetics"][args.name]["rarity"]
end

function p.isColorable(frame)
	local args = getArgs(frame)
	return cosmeticData["cosmetics"][args.name]["colorable"]
end

function p.getTrophiesAwarded(frame)
	local args = getArgs(frame)
	return cosmeticData["cosmetics"][args.name]["trophies"]
end

function p.isBonusTrophies(frame)
	local args = getArgs(frame)
	return cosmeticData["cosmetics"][args.name]["isBonusTrophies"]
end

function p.canBeDonated(frame)
	local args = getArgs(frame)
	return cosmeticData["cosmetics"][args.name]["canBeDonated"]
end

function p.getGlobalNumberOwned(frame)
	local args = getArgs(frame)
	return cosmeticData["cosmetics"][args.name]["globalNumberOwned"]
end

function p.getLastUpdatedDate()
	local lang = mw.language.getContentLanguage()
	return lang:formatDate( 'd F Y, h:i a', '@' .. cosmeticData['last_updated'], false ) .. ' UTC'
end

function p.lastUpdatedIcon()
    return string.format('<sup><abbr title="Data updated every 12 hours from MCC Island\'s API. Last updated on: %s" tabindex="0">ⓘ</abbr></sup>', p.getLastUpdatedDate())
end

return p