◆少前百科是非盈利性、非官方的少女前线维基百科。
◆如果您发现某些内容错误/空缺,请勇于修正/添加!参与进来其实很容易!点这里 加入少前百科
◆有任何意见、建议、纠错,欢迎在 GFwiki:反馈与建议 提出和讨论。编辑事务讨论QQ群:597764980,微博@GFwiki少前百科
◆To foreigners,You can use twitter to contact us.
Icon Nyto Silver.png

模块:TokenExchange

来自少前百科GFwiki
跳转至: 导航搜索

此模块的文档可以在模块:TokenExchange/doc创建

local p = {}
local args = {}
local origArgs = {}
local root
local count = 0

local function addRow(rowArgs)
	root:tag('tr')
		:tag('td'):wikitext(rowArgs.icon .. rowArgs.desc):done()
		:tag('td'):attr('data-num', rowArgs.num):done()
		:tag('td'):attr('id', 'price' .. tostring(count)):wikitext(rowArgs.price)
			:done()
		:tag('td'):attr('id', 'subtotal' .. tostring(count))
	count = count + 1
end

local function _main()
	root = mw.html.create('table'):attr('id', 'receipt'):addClass('stattable')
	local headers = {'奖励', '数量', '单价', '小计'}
	local headerRow = root:tag('tr')
	for i = 1, 4 do headerRow:tag('th'):wikitext(headers[i]) end
	for i = 1, 25 do
		local desc = args['desc' .. tostring(i)] or args['奖励' .. tostring(i)]
		local num = args['num' .. tostring(i)] or args['数量' .. tostring(i)]
		local price = args['price' .. tostring(i)] or args['单价' .. tostring(i)]
		if desc and desc ~= '' then
			if not (num or price) then error('Num or price not given.') end
			num = tonumber(num)
			price = tonumber(price)
			if not (num or price) then error('Nums and prices must be numbers.') end
			if num*price == 0 then error('Nums and prices cannot be 0.') end
			local icon = args['icon' .. tostring(i)] or args['图标' .. tostring(i)] or ''
			if icon ~= '' then icon = string.format('[[file:%s|48px]]', icon) end
			addRow{ icon = icon, desc = desc, num = num, price = price }
		end
	end
	root:tag('tr'):css{['text-align'] = 'center', ['font-weight'] = 'bold'}
		:tag('td'):wikitext('合计'):done():tag('td'):attr{colspan = 3, id = 'total'}
	return tostring(root)
end

function p.main(frame)
	args = frame == mw.getCurrentFrame() and frame:getParent().args or frame
	return _main()
end

return p