Module:CosmeticImage
From MCC Island Wiki
More actions
Documentation for this module may be created at Module:CosmeticImage/doc
local getArgs = require('Module:Arguments').getArgs
local cosmeticInfo = require('Module:CosmeticInfo')
local p = {}
local function getInfo(func, name)
return cosmeticInfo[func]({name = name})
end
-- Extract suffix, chroma, and evolved status
local function parseSuffix(name, page, defaultChroma)
-- Grab anything in parentheses after the name
local pattern = '^' .. name .. '%s*%((.-)%)%s*$'
local suffix = mw.ustring.match(page, pattern)
if not suffix then
return { chroma = defaultChroma, evolved = false }
end
-- Determine if it's evolved
local evolved = mw.ustring.find(suffix, 'Evolved', 1, true) ~= nil
-- Remove 'Evolved' and any trailing hyphen/space
local chroma = mw.text.trim((suffix:gsub('%-?%s*Evolved%s*', '')))
-- Fall back on default chroma if none present
if chroma == '' then
chroma = defaultChroma
end
return { chroma = chroma, evolved = evolved }
end
function p.categories(frame)
local args = getArgs(frame)
local name = args.name
local animated = args.animated
local page = mw.title.getCurrentTitle().text:gsub('%.%a+$', '')
local categories = {}
if animated and animated ~= '' then
table.insert(categories, '[[Category:Animated images]]')
end
local collection = getInfo('getCollection', name)
local rarity = getInfo('getRarity', name)
local defaultChromaSet = getInfo('getDefaultChromaSet', name)
local cosmeticType = getInfo('getType', name)
local rawCategory = getInfo('getCategory', name)
local categoryMap = { ['Accessory'] = 'Accessories', ['Hair'] = 'Hair' }
local pluralCategory = categoryMap[rawCategory] or (rawCategory:gsub('_', ' ') .. 's')
if cosmeticInfo.isWeaponSkin({name = name}) then
table.insert(categories, '[[Category:Images of ' .. name .. ']]')
table.insert(categories, '[[Category:Images of ' .. pluralCategory .. ']]')
local parsed = parseSuffix(name, page, defaultChromaSet)
local chroma = parsed.chroma
local isEvolved = parsed.evolved
if chroma == defaultChromaSet then
table.insert(categories, '[[Category:Images of weapon skins]]')
end
table.insert(categories, '[[Category:Images of weapon skins (' .. chroma .. ' Chroma Set)]]')
if isEvolved then
table.insert(categories, '[[Category:Images of evolved weapon skins]]')
end
table.insert(categories, '[[Category:Images of ' .. cosmeticType .. ' weapon skins]]')
table.insert(categories, '[[Category:Images of ' .. rarity .. ' weapon skins]]')
else
table.insert(categories, '[[Category:Images of ' .. pluralCategory .. ']]')
end
table.insert(categories, '[[Category:Images of ' .. cosmeticType .. ' cosmetics]]')
table.insert(categories, '[[Category:Images of ' .. rarity .. ' cosmetics]]')
table.insert(categories, '[[Category:Images of ' .. collection .. ' Collection cosmetics]]')
if cosmeticType == 'Limited' or cosmeticType == 'Collector' then
table.insert(categories, '[[Category:Images of tradeable cosmetics]]')
end
return table.concat(categories, '')
end
return p