Module:Cosmetic

-- Imports

local cargo = mw.ext.cargo local color = require('Module:Color')._main local getArgs = require('Module:Arguments').getArgs

-- Helper functions

local h = {}

function h.exists(file_name) success, result = pcall(function(file) return mw.title.new(file).fileExists end, file_name) return (success and result) end

-- Template

local p = {}

function p.main(frame) local args = getArgs(frame, {   wrappers = {      'Template:Cosmetic'    }  }) return p._main(args) end

function p._main(args) local icon = 'File:Cosmetic icon Blank.png' local size = args.userparam or args[2] or '100px' local border_color = '#a55858' local page = args.link or args[1] local name = args.text or args[1]

local cargo_output = cargo.query('cosmetic_items', 'image, rarity', {   where='_pageName="' .. args[1] .. '"',    groupBy='_pageID'  })[1] if cargo_output then icon = cargo_output.image border_color = color{('cos_' .. cargo_output.rarity):lower} elseif h.exists('File:Cosmetic icon ' .. args[1] .. '.png') then icon = 'File:Cosmetic icon ' .. args[1] .. '.png' end

local image = string.format('%s|link=%s|%s', icon, size, page, name) local link = string.format('%s', page, name)

return mw.html.create('div') :addClass('cosmetic-label') :css('width', size) :tag('div') :css('box-shadow', '0px 0px 2px 4px ' .. border_color) :wikitext(image) :done :wikitext(link) end

-- Return

return p