Dota 2 Вики
мНет описания правки
мНет описания правки
Строка 3: Строка 3:
 
--------------------------------------------------------------------------------
 
--------------------------------------------------------------------------------
   
local cargo = mw.ext.cargo
+
local cargo = require('Модуль:Cargo')
 
local color = require('Модуль:Color')._main
 
local color = require('Модуль:Color')._main
  +
local fileExists = require('Модуль:FileExists')
 
local getArgs = require('Модуль:Arguments').getArgs
 
local getArgs = require('Модуль: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
 
   
 
--------------------------------------------------------------------------------
 
--------------------------------------------------------------------------------
Строка 40: Строка 30:
 
local name = args.text or args[1]
 
local name = args.text or args[1]
   
local cargo_output = cargo.query('cosmetic_items', 'image, rarity', {
+
local output = cargo.query('cosmetic_items', 'image, rarity', {
 
where='_pageName="' .. args[1] .. '"',
 
where='_pageName="' .. args[1] .. '"',
 
groupBy='_pageID'
 
groupBy='_pageID'
 
})[1]
 
})[1]
  +
if cargo_output then
 
local output = {}
+
if output then
for k,v in pairs(cargo_output) do
 
if v ~= '' then output[k] = v end
 
end
 
 
icon = output.image
 
icon = output.image
 
border_color = color{('cos_' .. output.rarity):lower()}
 
border_color = color{('cos_' .. output.rarity):lower()}
  +
else
elseif h.exists('File:Cosmetic icon ' .. args[1] .. '.png') then
 
  +
-- Try to manually generate the icon by name.
icon = 'File:Cosmetic icon ' .. args[1] .. '.png'
 
 
local file_name = 'File:Cosmetic icon ' .. args[1] .. '.png'
  +
if fileExists(file_name) then
  +
icon = file_name
 
end
 
end
 
end
   

Версия от 21:13, 17 мая 2018

Документация для Модуль:Cosmetic Перейти к коду ↴ [ править | очистить ]

Reality Rift icon
▶️ Planeshift.
Документацию для этого шаблона или модуля можно найти в Template:Cosmetic.
Вы можете быть перенаправлены на другой язык вики, если перевод недоступен.


Зависимости

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

local cargo = require('Модуль:Cargo')
local color = require('Модуль:Color')._main
local fileExists = require('Модуль:FileExists')
local getArgs = require('Модуль:Arguments').getArgs

--------------------------------------------------------------------------------
-- Template
--------------------------------------------------------------------------------

local p = {}

function p.main(frame)
  local args = getArgs(frame, {
    wrappers = {
      'Шаблон: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 output = cargo.query('cosmetic_items', 'image, rarity', {
    where='_pageName="' .. args[1] .. '"',
    groupBy='_pageID'
  })[1]

  if output then
    icon = output.image
    border_color = color{('cos_' .. output.rarity):lower()}
  else
    -- Try to manually generate the icon by name.
    local file_name = 'File:Cosmetic icon ' .. args[1] .. '.png'
    if fileExists(file_name) then
      icon = file_name
    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