Module:Renewable resource row

Jump to navigation Jump to search

This module implements {{Renewable resource row}}.

Dependencies[edit source]

[view] [edit] [history] [refresh]The above documentation is transcluded from Module:Renewable resource row/doc.
local p = {}
p.row = function( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	local resource = mw.text.trim( args[1] or '' )
	local product = mw.text.trim( args[2] or '' )
	local slot = require( [[Module:Inventory slot]] )
	local sprite = require( [[Module:SpriteFile]] )
	local output = {}

	local title
	if args.title or '' ~= '' then
		title = args.title
	else
		local titles = {}
		for v in mw.text.gsplit( resource, '%s*,%s*' ) do
			local resources = slot.getParts( v ).name:gsub( '^Any ', '' )
			titles[ #titles + 1 ] = '[[' .. resources .. ']]'
		end
		title = mw.text.listToText( titles )
	end

	local function icon( var )
		local out = {}
		for icons in mw.text.gsplit( var, '%s*,%s*' ) do
			out[ #out + 1 ] = sprite.link{ icons, name = 'Invicon',
				align = 'middle', size = 32, keepcase = true, notext = true }
		end
		return table.concat( out )
	end

	table.insert(output, '|-' )

	local resourceicon = resource ~= '' and '<br>' .. icon( resource ) or ''

	table.insert(output, '| ' .. title .. resourceicon )

	local products
	if args.product or '' ~= '' then
		products = args.product
	elseif product ~= '' then
		products = icon( product )
	else
		products = '—'
	end

	table.insert(output, '| ' .. products )
	table.insert(output, '| ' .. ( args[3] or '' ) )

	return table.concat( output, '\n' )
end
return p