Модуль:SkillListLite
Версия от 12:12, 4 августа 2019; Medoke (обсуждение | вклад)
▶️
Planeshift.
Документацию для этого шаблона или модуля можно найти в Template:SkillListLite.
Вы можете быть перенаправлены на другой язык вики, если перевод недоступен.
Зависимости
--------------------------------------------------------------------------------
-- Imports
--------------------------------------------------------------------------------
local cargo = mw.ext.cargo
local aicon = require( 'Модуль:Ability icon' )._main
local color = require( 'Модуль:Color' )._main
local getArgs = require('Модуль:Arguments').getArgs
--------------------------------------------------------------------------------
-- Strings
--------------------------------------------------------------------------------
local i18n = {
error = {
category = 'Категория:Страницы с ошибками скриптов',
prefix = 'Ошибка Lua',
input_error = 'Ввод отсутствует или неполный',
no_data = 'Не найдено данных Cargo для "%s - %s"',
old_ability = '"%s - %s" это старая способность.[[Категория:Страницы, которые содержат старые способности]]'
}
}
--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------
local h = {}
--- Make a new li object.
-- @param text: The object's text.
-- @param background: The object's background-color.
function h.make_li(text, background)
return mw.html.create('li')
:addClass('skilllist-lite')
:css('background-color', background)
:wikitext(text)
end
--- Creates an error that fits into the list.
-- @param message: The error message.
function h.li_error(message)
return h.make_li(string.format('%s: %s.[[%s]]', i18n.error.prefix, message, i18n.error.category), '#c00')
end
--------------------------------------------------------------------------------
-- Template
--------------------------------------------------------------------------------
local p = {}
function p.main(frame)
local args = getArgs(frame, {
wrappers = {
'Шаблон:SkillListLite'
}
})
return p._main(args)
end
function p._main(args)
-- Check the input. We can't use assert() here since we want our custom error.
if not args and args.source and args.name then
return h.li_error(i18n.error.input_error)
end
-- Get the ability's data.
local data = cargo.query( 'abilities', 'image, type, game', {
where='uid="' .. args.source .. '&' .. args.name .. '"',
groupBy='source, title',
limit=1
} )[1]
if not data then return h.li_error(string.format(i18n.error.no_data, args.source, args.name)) end
if #args.name > 0 and #data.game > 0 then return h.li_error(string.format(i18n.error.old_ability, args.source, args.name)) end
data.image = aicon(args, data)
local image_link = string.format('[[%s|24px|link=%s#%s]]', data.image, args.source, args.name)
local source_link = string.format('[[%s|%s]]', args.source, (args.sourcetext or args.source))
local name_link = string.format('[[%s#%s|%s]]', args.source, args.name, (args.nametext or args.name))
return h.make_li((image_link .. ' ' .. source_link .. ' – ' .. name_link), color{data.type})
end
--------------------------------------------------------------------------------
-- Return
--------------------------------------------------------------------------------
return p