Module:Grid

Revision as of 02:03, 11 January 2015 by Binnie567 (talk | contribs)

Documentation for this module may be created at Module:Grid/doc

local p = {}
-- Individual cell
function p.grid(item)

    if (item == nil) then return { } end
    
    iCaption = nil

    local iNum= math.floor( string.match(item, ',%s*(%d+)' ) or 0 )
    local iName = string.match(item, '([%a%s]+),')
    if(iName == nil) then iName = item end

    if(iName:find("~")) then
        iCaption = string.match(iName, '([%a%s]+)~')
        iName = string.match(iName, '~([%a%s]+)')
    end

    paras = { }
    
    paras["name"] = iName
    
    if(iCaption ~= nil) then paras["caption"]=iCaption end
    if(iNum > 0) then paras["number"]=iNum end

    return paras
    
end

-- Gets a cell or animated cell
function p.cell(f, item) 
    
    if (item == nil) then return '' end
    
    if (item:find(';')) then 
        local text = '<div class=\"animated-grids\">'
 
        
        for frame in mw.text.gsplit( item, '%s*;%s*' ) do
            
            text = text .. '<span class=\"animated-grid\">'
            text = text .. f:expandTemplate{ title='Grid', args = p.grid(frame) }
            text = text .. '</span>'
            
        end

        text = text .. '</div>'
        
        return text
    end
    

   
    
    
    return f:expandTemplate{ title='Grid', args = p.grid(item) }
end

function p.liquid(f, item) 
    
    if (item == nil) then return '' end
    
    local text = ''
    
    for i=1,3,1 do
        text = text .. f:expandTemplate{ title='Grid', args = p.grid(item) }
    end

    return text
end


function p.craftingTable( f )

    local args = f
    
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end

    local sizeW = 3;
    local sizeH = 3;
    
    if(args.Size ~= nil and string.find(args.Size, 'Min') ~= nil) then
        
        if(args.C1 ~= nil or args.C2 ~= nil or args.C3 ~= nil) then
            sizeH = 3
        elseif(args.B1 ~= nil or args.B2 ~= nil or args.B3 ~= nil) then
            sizeH = 2
        else
            sizeH = 2
        end
        
        if(args.A3 ~= nil or args.B3 ~= nil or args.C3 ~= nil) then
            sizeW = 3
        elseif(args.A2 ~= nil or args.B2 ~= nil or args.C2 ~= nil) then
            sizeW = 2
        else
            sizeW = 2
        end
    
    end
    
    local gridArgs = { 
    
        A1=p.cell(f, args.A1),
        A2=p.cell(f, args.A2),
        A3=p.cell(f, args.A3),
        
        B1=p.cell(f, args.B1),
        B2=p.cell(f, args.B2),
        B3=p.cell(f, args.B3),
        
        C1=p.cell(f, args.C1),
        C2=p.cell(f, args.C2),
        C3=p.cell(f, args.C3),
        
        Output=p.cell(f, args.Output),
        
    }
    
    if(sizeH < 3) then gridArgs.HideRowC = "true" end
    if(sizeH < 2) then gridArgs.HideRowB = "true" end
    if(sizeW < 3) then gridArgs.HideColumn3 = "true" end
    if(sizeW < 2) then gridArgs.HideColumn2 = "true" end

   return f:expandTemplate{ title='Crafting', args= gridArgs}

end

function p.carpenter( f )

    local args = f
    
    if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
    
    local gridArgs = { 
        
        Liquid=p.liquid(f, args.Liquid),
    
        A1=p.cell(f, args.A1),
        A2=p.cell(f, args.A2),
        A3=p.cell(f, args.A3),
        
        B1=p.cell(f, args.B1),
        B2=p.cell(f, args.B2),
        B3=p.cell(f, args.B3),
        
        C1=p.cell(f, args.C1),
        C2=p.cell(f, args.C2),
        C3=p.cell(f, args.C3),
        
        Output=p.cell(f, args.Output),
        
    }

   return f:expandTemplate{ title='CraftingCarpenter', args= gridArgs}

end

function p.centrifuge( f )

    local args = f
    
    if f == mw.getCurrentFrame() then
    	args = f:getParent().args
	end
    
    local gridArgs = { 
        
        Input=p.cell(f, args.Input),
        
        Output1=p.cell(f, args.Output1),
        Output2=p.cell(f, args.Output2),
        
        Output1chance=args.Output1chance
    }

   return f:expandTemplate{ title='CraftingCentrifuge', args= gridArgs}

end

function p.incubator( f )

    local args = f
    
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end

    local gridArgs = { 
        Item=p.cell(f, args.Item),
        Liquid=p.liquid(f, args.Liquid),
        Output=p.cell(f, args.Output),
        LiquidOutput=p.liquid(f, args.LiquidOutput)
    }


   return f:expandTemplate{ title='CraftingIncubator', args= gridArgs}

end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Need wiki hosting?

Do you need a wiki for your Minecraft mod/gaming wiki? We'll host it for free! Contact us.

Other wikis

Indie-game wikis
Powered by Indie Wikis