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: Difference between revisions

From MCC Island Wiki
Created function p.isInCrateCollection()
Added isInGamePassCollection function
Line 55: Line 55:
["Natural"] = true,
["Natural"] = true,
["Magical"] = true
["Magical"] = true
}
return allowed[collection]
end
function p.isInGamePassCollection(frame)
local args = getArgs(frame)
local collection = cosmeticData["cosmetics"][args.name]["collection"]
local allowed = {
["Battle Box"] = true,
["Dynaball"] = true,
["HITW"] = true,
["Parkour Warrior"] = true,
["Sky Battle"] = true,
["TGTTOS"] = true
}
}

Revision as of 15:50, 21 June 2025

This module uses info gathered from the API and stored in the data page to:

It is also invoked by other modules, such as Module:CosmeticMachine and Module:CosmeticCrates.


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.isInCrateCollection(frame)
	local args = getArgs(frame)
	local collection = cosmeticData["cosmetics"][args.name]["collection"]
	
	local allowed = {
		["Oceanic"] = true,
		["Mechanical"] = true,
		["Natural"] = true,
		["Magical"] = true
	}
	
	return allowed[collection]
end

function p.isInGamePassCollection(frame)
	local args = getArgs(frame)
	local collection = cosmeticData["cosmetics"][args.name]["collection"]
	
	local allowed = {
		["Battle Box"] = true,
		["Dynaball"] = true,
		["HITW"] = true,
		["Parkour Warrior"] = true,
		["Sky Battle"] = true,
		["TGTTOS"] = true
	}
	
	return allowed[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