本站文本内容除另有声明外,转载时均必须注明出处,并遵守CC BY-NC-SA 3.0协议。(转载须知
本站是中文Minecraft Wiki的镜像站,与Mojang Studios、Weird Gloop没有从属关系。(免责声明

全站通知:

模块:Layered blueprint

来自我的世界地下城WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块用于实现{{layered blueprint}}

依赖

local p = {}
local getLayerSize = function( data )
	local width = 0
	local height = #data
	for _, v in ipairs( data ) do
		width = math.max( #v, width )
	end
	
	return width, height
end
p.main = function( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end

	local blockGrid = require( [[Module:Sprite grid]] ).grid
	local keys = {}
	for k, v in pairs( args ) do
		if type( k ) == 'string' and #k == 1 then
			keys[k] = v
		end
	end
	
	local layerNames = {}
	local layers = {}
	local width = 0
	local height = 0
	local scale = args.scale or 1
	for _, v in ipairs( args ) do
		if v:match( '%-%-%-%-' ) then
			table.insert( layerNames, mw.text.trim( string.sub( v, 5 ) ) )
		else
			local data = mw.text.split( mw.text.trim( v, '\n' ), '\n' )
			local layerWidth, layerHeight = getLayerSize( data )
			width = math.max( layerWidth, width )
			height = math.max( layerHeight, height )
			data.keys = keys
            data.scale = scale
            data.sheet = args.sheet
            data.nolink = args.nolink
			table.insert( layers, blockGrid( data ) )
		end
	end
	
	local name = args.name:gsub( ' ', '_' )
	local defaultLayer = args.default
	local body = mw.html.create( 'div' ):addClass( 'layered-blueprint' ):css( {
		width = width * 16 * scale .. 'px',
		['min-height'] = height * 16 * scale .. 'px'
	} )
	for i, v in ipairs( layerNames ) do
		local tab_div = mw.html.create( 'div' )

		tab_div
			:attr( 'id', name .. '-layer' .. i )
			:attr( 'class', 'layered-blueprint-tab' )
			:attr( 'data-name', name )
			:attr( 'data-checked', tostring( v == defaultLayer or not defaultLayer and i == 1 ) )
			:wikitext( v )
		
		body:wikitext( tostring( tab_div ) )
		body:tag( 'div' ):addClass( 'layered-blueprint-layer' ):newline():wikitext( layers[i] )
	end
	
	return body
end
return p