Minecraft Wiki

EN SAVOIR PLUS

Minecraft Wiki
Advertisement
Minecraft Wiki
[créer | historique | purger]Documentation
Ce module n'a pas de documentation. Si vous savez comment l'utiliser, merci de la créer.
local p = {}

function p.grid( f )

	local args = f
	
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
	
	local rows = {}
	local sprite = require( [[Module:Sprite]] )
	local scale = args.scale
	local size = 16 * ( scale or 1 )
	local categories = {}
	local keys = args.keys or args
	local baseSheet = args.sheet or 'BlocSprite'
	
	for k, v in ipairs( args ) do
	
		local row = {}
		
		for v2 in mw.text.gsplit( v:gsub( '^%s-\n+', '' ):gsub( '\n+%s-$', '' ), '' ) do
		
			local spriteName = keys[v2]
			
			if mw.text.trim( v2 ) == '' or spriteName == 'air' then
			
				row[#row + 1] = ' style="width:' .. size .. 'px;height:' .. size .. 'px" | '
				
			else
			
				local sheet = baseSheet
				local css
				local includeLink = true
				
				if spriteName then
					local spritePart = mw.text.split( spriteName, '-rot', true )
					spriteName = spritePart[1]
					if spritePart[2] then
						css = 'transform:rotate(' .. spritePart[2] .. 'deg)'
					end
					if spriteName:find(':') then
						local sheetSplit = mw.text.split( spriteName, ':')
						sheet = sheetSplit[1]
							spriteName = sheetSplit[2]
					end
				end
				
				if spriteName and spriteName:sub(1, 1) == '+' then
					includeLink = false
					spriteName = spriteName:sub(2)
				end
				
				local image, spriteCat 
				local spriteData = {
					data = sheet,
					spriteName,
					scale = scale,
					notext = 1,
					nocat = args.nocat,
					css = css
				}
				
				if includeLink then
					image, spriteCat = sprite.link(spriteData)
				else
					image, spriteCat = sprite.sprite(spriteData)
				end
				
				row[#row + 1] = image
				categories[#categories + 1] = spriteCat
			end
		end
		
		rows[k] = table.concat( row, ' || ' )
	end
	
	local spacing = tonumber( args.spacing or '' ) or 0
	
	return '{| cellspacing="' .. spacing .. '" cellpadding="0" style="margin:0; line-height:0"\n| ' ..
		table.concat( rows, '\n|-\n| ' ) ..
	'\n|}' .. table.concat( categories )
	
end
return p
Advertisement