▶️
Planeshift.
该module的文档可以在Template:SkillListLite找到。
You may be forwarded to another wiki language, in case a translation is not available.
--------------------------------------------------------------------------------
-- Imports
--------------------------------------------------------------------------------
local cargo = mw.ext.cargo
local aicon = require( 'Module:Ability icon' )._main
local color = require( 'Module:Color' )._main
local getArgs = require('Module:Arguments').getArgs
--------------------------------------------------------------------------------
-- Strings
--------------------------------------------------------------------------------
local i18n = {
error = {
category = 'Category:有脚本错误的页面',
prefix = 'Lua错误',
input_error = '缺少或未完成输入',
no_data = '没有找到"%s - %s"的Cargo数据',
old_ability = '"%s - %s"是一个旧的技能。[[Category:包含旧的技能的页面]]'
}
}
--------------------------------------------------------------------------------
-- 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 = {
'Template: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