模块:图标
本模块有两种工作模式
1.将带数量和分隔符的字符串解析为图标模板
{{#invoke:图标|expandTemplate|str=<源字符串>|ptype=<可选,图标模板类型,默认为空>|sep=<可选,输出的分隔符,默认为空>}}
其中ptype参数对应模板:图标中的第二个参数。
例如:
| 使用本模块的写法 | 等价写法 | 效果 |
|---|---|---|
{{#invoke:图标|expandTemplate|str=神石*2、红石*2、洪门道服*1}}
|
{{图标|神石|2}}{{图标|红石|2}}{{图标|洪门道服|1}}
|
Lua错误:无法创建进程:proc_open(/dev/null): Failed to open stream: Operation not permitted |
{{#invoke:图标|expandTemplate|str=神石*2、红石*2、洪门道服*1|ptype=材料|sep=<br>}}
|
{{图标|材料|神石|2}}<br>{{图标|材料|红石|2}}<br>{{图标|材料|洪门道服|1}}
|
Lua错误:无法创建进程:proc_open(/dev/null): Failed to open stream: Operation not permitted |
注意数量的显示需要对应类型的模板:图标支持
2.将带数量和分隔符的字符串解析为Set函数(不保留数量)
{{#invoke:图标|expandSet|str=<源字符串>|pname=<用于set的属性值名称>}}
| 使用本模块的写法 | 等价写法 |
|---|---|
{{#invoke:图标|expandSet|str=神石*2、红石*2、洪门道服*1|pname=所需食材}}
|
{{#set:|所需食材=神石、红石、洪门道服|+sep=、}}
|
脚本错误:Lua错误:无法创建进程:proc_open(/dev/null): Failed to open stream: Operation not permitted
local p={}
function p.expandSet(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local str = args['str'] or '' -- 待处理字符串
local pname = args['pname'] or '' -- 输出参数名称
if (str=='' or pname=='') then
return ''
end
local paratable = {}
local result = ''
local strtable = mw.text.split(str, '、')
local itemtable = {}
local itemname, itemcount = '', 0
for i = 1, #strtable do
itemtable = mw.text.split(strtable[i],'*')
itemname = itemtable[1]
paratable[#paratable+1] = itemname
end
local parastr = table.concat(paratable,'、')
result = frame:callParserFunction{ name = '#set', args = { pname..'='..parastr,'+sep=、'} }
mw.log(result)
return result
end
function p.expandTemplate(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local str = args['str'] or '' -- 待处理字符串
if (str=='') then
return ''
end
local ptype = args['ptype'] or '' -- 图标模板类型
local sep = args['sep'] or '' -- 输出的分隔符
local paratable = {}
local resulttable = {}
local result = ''
local strtable = mw.text.split(str, '、')
local itemtable = {}
local itemname, itemcount = '', 0
for i = 1, #strtable do
itemtable = mw.text.split(strtable[i],'*')
itemname = itemtable[1]
itemcount = itemtable[2]
if (ptype=='') then
resulttable[#resulttable+1] = frame:expandTemplate{ title = '图标', args = { itemname, itemcount} }
else
resulttable[#resulttable+1] = frame:expandTemplate{ title = '图标', args = { ptype, itemname, itemcount} }
end
end
result = table.concat(resulttable,sep)
mw.log(result)
return result
end
function p.expandWeaponTemplate(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local str = args['str'] or '' -- 待处理字符串
if (str=='') then
return ''
end
local sep = args['sep'] or '' -- 输出的分隔符
local paratable = {}
local resulttable = {}
local result = ''
local strtable = mw.text.split(str, '、')
local itemtable = {}
local itemname, itemcount = '', 0
for i = 1, #strtable do
itemtable = mw.text.split(strtable[i],'*')
itemname = itemtable[1]
itemcount = itemtable[2]
resulttable[#resulttable+1] = frame:expandTemplate{ title = '武器图鉴/材料', args = { itemname, itemcount} }
end
result = table.concat(resulttable,sep)
mw.log(result)
return result
end
return p
