本WIKI由旅行者酒馆于2020年03月14日申请开通,内容按CC-BY-NC-SA4.0协议提供,编辑权限开放。感谢 大猫雷恩 对WIKI设计支持,期待更多能人异士加入原神WIKI中

交流群:1087445447  ·  QQ频道:i3h65u03kv

全站通知:

模块:图标

来自原神WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

本模块有两种工作模式

1.将带数量和分隔符的字符串解析为图标模板

{{#invoke:图标|expandTemplate|str=<源字符串>|ptype=<可选,图标模板类型,默认为空>|sep=<可选,输出的分隔符,默认为空>}}

其中ptype参数对应模板:图标中的第二个参数。

例如:

使用本模块的写法 等价写法 效果
{{#invoke:图标|expandTemplate|str=兽肉*2、奶油*2、金鱼草*1}}
{{图标|兽肉|2}}{{图标|奶油|2}}{{图标|金鱼草|1}}
兽肉  兽肉 × 2 奶油  奶油 × 2 金鱼草  金鱼草 × 1 
{{#invoke:图标|expandTemplate|str=兽肉*2、奶油*2、金鱼草*1|ptype=材料|sep=<br>}}
{{图标|材料|兽肉|2}}<br>{{图标|材料|奶油|2}}<br>{{图标|材料|金鱼草|1}}


注意数量的显示需要对应类型的模板:图标支持


2.将带数量和分隔符的字符串解析为Set函数(不保留数量)

{{#invoke:图标|expandSet|str=<源字符串>|pname=<用于set的属性值名称>}}
使用本模块的写法 等价写法
{{#invoke:图标|expandSet|str=兽肉*2、奶油*2、金鱼草*1|pname=所需食材}}
{{#set:|所需食材=兽肉、奶油、金鱼草|+sep=、}}


编辑文档


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