Dota 2 Wiki
Advertisement
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

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


Dependencies

--------------------------------------------------------------------------------
-- Imports
--------------------------------------------------------------------------------

local cargo = require('Module:Cargo')
local color = require('Module:Color')._main
local fileExists = require('Module:FileExists')
local getArgs = require('Module:Arguments').getArgs

--------------------------------------------------------------------------------
-- 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 ' .. args[1] .. '.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 output = ( cargo.query('cosmetic_items', 'image, rarity, title', {
    where='_pageName="' .. args[1] .. '"',
    groupBy='_pageID'
  }) or {} )[1]

  if output then
    if output.image then icon = output.image end
    if output.rarity then border_color = color{('cos_' .. output.rarity):lower()} end
    if output.title then name = output.title end
  end

  local image = string.format('[[%s|%s|link=%s|%s]]', icon, size, page, name)
  local link = string.format('[[%s|%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
Advertisement