Module:Data value table

Jump to navigation Jump to search
Documentation[create] [refresh]
This module has no documentation. If you know how to use this module, please create it.
local p = {}

function p.main(f)
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	
	local sf = require('Module:SpriteFile')
	
	local stype = 'BlockSprite'
	if args.spritetype == 'item' then 
		stype = 'ItemSprite'
	elseif args.spritetype == 'entity' then
		stype = 'EntitySprite'
	end
	
	local output = {}
	
	table.insert(output, '<table class="wikitable collapsible" style="text-align: center">'..
		'<tr><th></th><th>[[Data values|DV]]</th><th>Description</th></tr>')
	
	local items = {}
	for k, v in pairs( args ) do
		if type( k ) == 'string' then
			local item = k:match( '(%d+)' )
			if item and v then
				table.insert( items, tonumber( item ) )
			end
		end
	end
	table.sort( items )
	
	for _, v in ipairs( items ) do
		table.insert( output, '<tr><td>' )
		local sprite = args['sprite' .. v]
		
		if args[v] == '-' then
			table.insert( output, sf.sprite{ 'Air', name='BlockSprite'} .. '</td><td>' .. '<span style="color:gray">(unused)</span>' .. '</td><td>' .. args[v])
		else
			if sprite then
				table.insert( output, sf.sprite{ sprite, name = stype } .. '</td><td>' .. v .. '</td><td>' .. args[v] )
			else
				table.insert( output, sf.sprite{ 'Air', name='BlockSprite'} .. '</td><td>' .. v .. '</td><td>' .. args[v])
			end
		end
		
		table.insert( output, '</td></tr>' )
		
	end
	return table.concat(output)
end

return p