本站文本内容除另有声明外,转载时均必须注明出处,并遵守CC BY-NC-SA 3.0协议。(转载须知)
本站是中文Minecraft Wiki的镜像站,与Mojang Studios、Weird Gloop没有从属关系。(免责声明)
全站通知:
模块:Ingredient link list
刷
历
编
跳到导航
跳到搜索
创建一个适用于含有游戏内UI的表格模板的材料链接列表。
此模块不应在内容页面上直接引用,应在模板中调用。参数如下:
|firstarg=
:可选,数值。用于指定首个需要处理的匿名参数,未设置时为1。|maxargs=
:可选(|firstarg=2
及以上时必填,否则返回错误代码2),数值。用于限制需要处理的匿名参数数量,未设置时为匿名参数总数-1。|sep=
:可选,字符串。用于指定匿名参数中各名称间的分隔符,默认为;
。- (匿名参数):字符串。用于生成链接的原始字符串。其中第一个匿名参数为必填项,否则返回错误代码1。
入口点:
main
:模板调用入口点。genlink
:模块调用入口点。
local p = {}
local f = mw.getCurrentFrame()
local autoLink = require( 'Module:Autolink' ).invlink
function p.genlink(args)
if args[1] == nil then
return { errno = 1 }
end
local sep = args.sep or ';'
local firstarg = args.firstarg or 1
if tonumber(firstarg) >= 2 and (not args.maxargs) then
return { errno = 2 }
end
local maxargs = args.maxargs or (#args - 1)
local output_array = {}
for i = firstarg, maxargs do
local name_pieces = {}
for current_name in mw.text.gsplit(mw.text.trim(args[i]), sep) do
local trimmed_name = mw.text.trim(current_name)
if trimmed_name ~= '' then
name_pieces[trimmed_name] = true
end
end
local converted_names = {}
for name, exist in pairs(name_pieces) do
if exist then
local prefix
if string.find(name, '^Matching ') then
prefix = '对应'
name = string.gsub(name, '^Matching ', '')
elseif string.find(name, '^Any ') then
prefix = '任意'
name = string.gsub(name, '^Any ', '')
else
prefix = ''
end
table.insert(converted_names, f:preprocess(prefix .. '[[' .. autoLink(name) .. ']]'))
end
end
table.insert(output_array, table.concat(converted_names, '或<br>'))
end
return table.concat(output_array, ' +<br>')
end
function p.main()
local args = require('Module:ProcessArgs').merge(true)
local result = p.genlink(args)
if type(result) == 'string' then
return result
end
local error_prompts = {
'首个匿名参数不能为空!',
'参数“firstarg”大于等于2时,参数“maxargs”必须指定!'
}
return f:expandTemplate{ title = 'Error', args = { error_prompts[result.errno] } }
end
return p