Module:Cosmetic

From Dota 2 Wiki
Jump to: navigation, search

Documentation for Module:Cosmetic Jump to code ↴ [ edit | purge ]

Reality Rift icon.png
Play “Planeshift.”
The documentation for this template or module can be found at Template:Cosmetic.
You may be forwarded to another wiki language, in case a translation is not available.


Dependencies

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

local i18n = {
  error = {
    no_input = 'No input given',
  }
}


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

function p._main(args)
  assert(args[1], i18n.error.no_input)

  local icon = 'File:Cosmetic icon ' .. args[1] .. '.png'
  local border = 'cos_common'
  local size = args['userparam'] or args[2] or '100px'
  local link = args['link'] or args[1]
  local name = args['text'] or args[1]

  -- Try getting data from the cargo table.
  local cargo_output = cargo.query('cosmetic_items', 'image, rarity', { where='_pageName="' .. args[1] .. '"', groupBy='_pageID' })[1]
  if cargo_output then
    border = 'cos_' .. string.lower(cargo_output['rarity'])
    icon = cargo_output['image']
  end

  return mw.html.create('div')
    :addClass('cosmetic-label')
    :css('width', size)
    :tag('div')
      :css('box-shadow', '0px 0px 2px 4px ' .. color({ border }))
      :wikitext(string.format('[[%s|%s|link=%s|%s]]', icon, size, link, name))
      :done()
    :wikitext(string.format('[[%s|%s]]', link, name))
end


return p
Promotional Content