モジュール:Build

提供:Minecraft Japan Wiki
ナビゲーションに移動 検索に移動

このモジュールについての説明文ページを モジュール:Build/doc に作成できます

local p = {}
function p.base( f )

	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end

    local scale = args.scale or 2

    ------------------------------

	local function split (inputstr, sep)
	        if sep == nil then
	                sep = "%s"
	        end
	        local t={}
	        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
	                table.insert(t, str)
	        end
	        return t
	end

    -------------------------
    local div = mw.html.create( 'div' )
    div :addClass( 'sc-container' )
    
    local previous_layer = nil
    local depth = 0
    local max_width = 0
    local max_height = 0

    local layers = {}

    --------- layers
    for k, v in pairs( args )
    do
        if string.match( k, '^layer[0-9]+$') then
		    local width = 0
		    local height = 0

            local lines = split(v, ",")

            local rows = {}
            
            local index = string.match( k, '^layer([0-9]+)$')

            ------ rows
            for lk, lv in pairs( lines )
            do
				height = height + 1
		    	width = 0
				
                local wikitext = ""

                local sprites = split(lv, ";")

                ---------- sprites
                for sk, sv in pairs( sprites )
                do
                	width = width + 1

                    local sprite = {args={}}
                    if string.find(sv, "schema:") then
                    	sprite.title="SchematicSprite"
                    	local s = string.find(sv, ":")
                    	sprite.args = { string.sub(sv, s+1), scale = scale }
                    else
                    	if mw.text.trim(sv) == 'air' then
                    		sprite.title="SchematicSprite"
                    	else
                    		sprite.title="LBlockSprite"
                    	end
                    	sprite.args = { sv, scale = scale }
                    	if args["notip"] then
							sprite.args["notip"] = "1"
						end
                    end
        
                    wikitext = wikitext .. tostring(f:expandTemplate(sprite))

                end

                table.insert(rows, wikitext)
            
                if width > max_width then
                    max_width = width
                end
            end

            layers[tonumber(index)] = rows

            if height > max_height then
            	max_height = height
            end
            
        end
    end

    ---------------------------------------------------
    local lower_depth = 4 - (table.getn(layers));
    
    for i, layer_data in ipairs(layers)
    do
        	
        if previous_layer then
            local opacity = (lower_depth + depth) / 4
            if opacity < 0 then
            	opacity = 0
            end
            previous_layer:css("opacity", opacity)
        end

        local layer = div:tag( 'div' )
        layer :addClass( 'sc-layer' )

        for j, row_data in ipairs(layer_data)
        do
            local row = layer:tag( 'div' )
            row :addClass( 'sc-row' )
                :wikitext( row_data )
        end
            
        previous_layer = layer
        depth = depth + 1

        layer:css("width", (max_width * 16 * scale) .. "px")
        layer:css("height", (max_height * 16 * scale) .. "px")
    end
    
    div:css("width", (max_width * 16 * scale) .. "px")
    div:css("height", (max_height * 16 * scale) .. "px")

    ------------------------------------------------
    return tostring(div)

end

return p
Cookieは私達のサービスを提供するのに役立ちます。このサービスを使用することにより、お客様はCookieの使用に同意するものとします。