Dota 2 Вики
Регистрация
мНет описания правки
мНет описания правки
 
(не показано 7 промежуточных версий 2 участников)
Строка 1: Строка 1:
  +
--------------------------------------------------------------------------------
local cargo = mw.ext.cargo
 
  +
-- Imports
local color = require('Module:Color')._main
 
  +
--------------------------------------------------------------------------------
local getArgs = require('Module:Arguments').main
 
  +
  +
local cargo = require('Модуль:Cargo')
 
local color = require('Модуль:Color')._main
  +
local fileExists = require('Модуль:FileExists')
 
local getArgs = require('Модуль:Arguments').getArgs
  +
  +
--------------------------------------------------------------------------------
  +
-- Template
  +
--------------------------------------------------------------------------------
  +
 
local p = {}
 
local p = {}
   
function p.main()
+
function p.main(frame)
local args = getArgs()
+
local args = getArgs(frame, {
  +
wrappers = {
  +
'Шаблон:Cosmetic'
  +
}
  +
})
 
return p._main(args)
 
return p._main(args)
 
end
 
end
   
 
function p._main(args)
 
function p._main(args)
assert(args[1], 'Не введен косметический предмет')
 
 
 
local icon = 'File:Cosmetic icon ' .. args[1] .. '.png'
 
local icon = 'File:Cosmetic icon ' .. args[1] .. '.png'
local border = 'cos_common'
+
local size = args.userparam or args[2] or '100px'
local size = args['userparam'] or args[2] or '100px'
+
local border_color = '#a55858'
local link = args['link'] or args[1]
+
local page = args.link or args[1]
local name = args['text'] or args[1]
+
local name = args.text or args[1]
   
  +
local output = ( cargo.query('cosmetic_items', 'image, rarity, title', {
-- Try getting data from the cargo table.
 
local cargo_output = cargo.query('cosmetic_items', 'image, rarity', { where='_pageName="' .. args[1] .. '"', groupBy='_pageID' })[1]
+
where='_pageName="' .. args[1] .. '"',
  +
groupBy='_pageID'
if cargo_output then
 
  +
}) or {} )[1]
border = 'cos_' .. string.lower(cargo_output['rarity'])
 
  +
icon = cargo_output['image']
 
 
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
 
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')
 
return mw.html.create('div')
:attr('class', 'cosmetic-label')
+
:addClass('cosmetic-label')
:css('margin-left', '6px')
 
:css('margin-right', '6px')
 
 
:css('width', size)
 
:css('width', size)
  +
:tag('div')
:wikitext('<div style="box-shadow:0px 0px 2px 4px ' .. color({ border }) .. '>[[' .. icon .. '|' .. size .. '|link=' ..link .. '|' .. name .. ']]</div>[[' .. link .. '|' .. name .. ']]')
 
  +
:css('box-shadow', '0px 0px 2px 4px ' .. border_color)
  +
:wikitext(image)
  +
:done()
  +
:wikitext(link)
 
end
 
end
  +
  +
--------------------------------------------------------------------------------
  +
-- Return
  +
--------------------------------------------------------------------------------
   
 
return p
 
return p

Текущая версия от 11:42, 9 августа 2021

Документация для Модуль: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 ' .. 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