Module:CosmeticInfo: Difference between revisions
From MCC Island Wiki
More actions
Functions for all other fields |
getAllData function Tag: Reverted |
||
Line 74: | Line 74: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
return cosmeticData["cosmetics"][args.name]["globalNumberOwned"] | return cosmeticData["cosmetics"][args.name]["globalNumberOwned"] | ||
end | |||
function p.getAllData(frame) | |||
local args = getArgs(frame) | |||
local name = args.name | |||
local cosmetic = cosmeticData["cosmetics"][name] | |||
if not cosmetic then | |||
return nil | |||
end | |||
return { | |||
description = p.getDescription(frame), | |||
type = p.getType(frame), | |||
collection = p.getCollection(frame), | |||
rarity = p.getRarity(frame), | |||
colorable = p.isColorable(frame), | |||
trophies = p.getTrophiesAwarded(frame), | |||
isBonusTrophies = p.isBonusTrophies(frame), | |||
canBeDonated = p.canBeDonated(frame), | |||
globalNumberOwned = p.getGlobalNumberOwned(frame), | |||
lastUpdated = p.getLastUpdatedDate(), | |||
lastUpdatedIcon = p.lastUpdatedIcon() | |||
} | |||
end | end | ||
Revision as of 09:07, 15 March 2025
This module uses info gathered from the API and stored in the data page to:
- greatly simplify creating pages for cosmetics via Template:Cosmetic
- generate the bulk of the Tradeable Cosmetics page
- output lists of cosmetics based on particular field values
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.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.getAllData(frame)
local args = getArgs(frame)
local name = args.name
local cosmetic = cosmeticData["cosmetics"][name]
if not cosmetic then
return nil
end
return {
description = p.getDescription(frame),
type = p.getType(frame),
collection = p.getCollection(frame),
rarity = p.getRarity(frame),
colorable = p.isColorable(frame),
trophies = p.getTrophiesAwarded(frame),
isBonusTrophies = p.isBonusTrophies(frame),
canBeDonated = p.canBeDonated(frame),
globalNumberOwned = p.getGlobalNumberOwned(frame),
lastUpdated = p.getLastUpdatedDate(),
lastUpdatedIcon = p.lastUpdatedIcon()
}
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