Difference between revisions of "Module:Grid"

From Industrial-Craft-Wiki
Jump to navigation Jump to search
m (This might make it nicer to read outside of the editor)
m (Pre-emptive testing)
Line 75: Line 75:
end
end


 
--[[
function p.liquid(f, item)  
function p.liquid(f, item)  
   
   
Line 88: Line 88:
     return text
     return text
end
end
--]]
   
   
function p.gc ( f )
function p.gc ( f )
Line 133: Line 133:
end
end


--[=[
function p.furnace( f )
function p.carpenter( f )
   
   
     local args = f
     local args = f
Line 143: Line 142:
   
   
     local gridArgs = {  
     local gridArgs = {  
         Input=p.cell(f, (args.Input or args.Top)),
        Liquid=p.liquid(f, args.Liquid),
         Fuel=p.cell(f, (args.Fuel or args.Bottom)),
        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),
         Output=p.cell(f, args.Output),
        Break=args.Break
     }
     }
   
   
   return f:expandTemplate{ title='CraftingCarpenter', args= gridArgs}
   return f:expandTemplate{ title='Crafting/Furnace', args= gridArgs}
   
   
end
end
   
   
function p.centrifuge( f )
 
function p.turningNumber(number)
    local args = f
if number == 1 then return 22
elseif number == 2 then return 44
    if f == mw.getCurrentFrame() then
elseif number == 3 then return 66
    args = f:getParent().args
elseif number == 4 then return 88
else return 110
end
end
    local gridArgs = {
        Input=p.cell(f, args.Input),
        Output1=p.cell(f, args.Output1),
        Output2=p.cell(f, args.Output2),
        Output3=p.cell(f, args.Output3)
    }
  return f:expandTemplate{ title='CraftingCentrifuge', args= gridArgs}
end
end
--]=]
function p.furnace( f )
   
   
    local args = f
   
   
    if f == mw.getCurrentFrame() then
function p.turning(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
args = f:getParent().args
end
end
local gridArgs = {Return = 1, Output=p.cell(f, args.Output)}
    local gridArgs = {  
        Input=p.cell(f, (args.Input or args.Top)),
if args.Output == nil then return f:expandTemplate{title='Grid/Turning Table', args=gridArgs} end
        Fuel=p.cell(f, (args.Fuel or args.Bottom)),
        Output=p.cell(f, args.Output),
gridArgs.Type = string.sub(mw.text.split(args.Output,"%s* %s*")[1],2,-1)
        Break=args.Break
local valid = {Wooden=true, Iron=true}
    }
if valid[gridArgs.Type] == nil then
--Someone's done a boo boo.
  return f:expandTemplate{ title='Crafting/Furnace', args= gridArgs}
return f:expandTemplate{title='Grid/Turning Table', args=gridArgs}
end
if gridArgs.Type == 'Wooden' then
local bounce = 3
else
local bounce = 5
end
if args.Layout:find(',') then
local layout = mw.text.split(args.Layout,"%g*,%g*")
gridArgs.n1 = p.turningNumber(layout[0])
gridArgs.n2 = p.turningNumber(layout[1])
gridArgs.n3 = p.turningNumber(layout[2] or bounce)
gridArgs.n4 = p.turningNumber(layout[3] or bounce)
gridArgs.n5 = p.turningNumber(layout[4] or bounce)
else
bounce = p.turningNumber(bounce)
gridArgs.n1 = bounce
gridArgs.n2 = bounce
gridArgs.n3 = bounce
gridArgs.n4 = bounce
gridArgs.n5 = bounce
end
return f:expandTemplate{title='Grid/Turning Table', args=gridArgs}
end
end
   
   
return p
return p
--</syntaxhighlight>
--</syntaxhighlight>

Revision as of 21:17, 13 March 2015

Template-info.png Documentation

This module is a WIP (work in progress), but is still being called by {{Grid/Crafting Table}}, so any changes should be tested to avoid inconvenience.

Related Links[edit]

The above documentation is transcluded from Module:Grid/doc. (edit | history)


--<syntaxhighlight lang="lua">
local p = {}
-- Individual cell
function p.grid(item)
 
    if (item == nil) then return { } end
 
    local iLink = nil
    local iNum= math.floor( string.match(item, ',%s*(%d+)' ) or 0 )
    local iName = string.sub(string.match(item, '.+,') or item..' ', 1, -2)
    local tooltip = string.match(item, '%[.+%]')
    if tooltip ~= nil then
    	iName = string.sub(iName, string.len(tooltip)+1)
    	tooltip = string.sub(tooltip,2,-2)
    end
    local hasPercentage = string.match(item, "[%%]")
 
	local aliases = mw.loadData('Module:Grid/Aliases')
	if tooltip == nil then
		if aliases[iName] then
			tooltip = aliases[iName]
		end
	else
		if aliases[tooltip] then
			tooltip = aliases[tooltip]
		end
	end

    if(iName:find("~")) then
        iLink = string.match(iName, '~([%a%s-]+)')
        iName = string.match(iName, '([%a%s-]+)~')
    end
 
    paras = { }
 
    paras["name"] = iName
 
    if(iLink ~= nil) then paras["link"]=iLink end
    if(iNum > 1 or hasPercentage) then paras["number"]=iNum end
    if(hasPercentage) then paras["percent"]="x" end
    if(tooltip ~= nil) then paras["tooltip"]=tooltip 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\">'
            if frame == 'Blank' or frame == 'blank' then
               text = text .. ''
            else
               text = text .. f:expandTemplate{ title='Grid', args = p.grid(frame) }
            end
            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.gc ( f )

   local args = f

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

   return p.cell(f, (args[1] or args.name))
end


function p.craftingTable( f )
 
    local args = f
 
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	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),
 
        Break=args.Break
    }

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

function p.furnace( f )
 
    local args = f
 
    if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
 
    local gridArgs = { 
        Input=p.cell(f, (args.Input or args.Top)),
        Fuel=p.cell(f, (args.Fuel or args.Bottom)),
        Output=p.cell(f, args.Output),
        Break=args.Break
    }
 
   return f:expandTemplate{ title='Crafting/Furnace', args= gridArgs}
 
end
 

function p.turningNumber(number)
	if number == 1 then return 22
	elseif number == 2 then return 44
	elseif number == 3 then return 66
	elseif number == 4 then return 88
	else return 110
	end
end
 
 
function p.turning(f)
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
	local gridArgs = {Return = 1, Output=p.cell(f, args.Output)}
	
	if args.Output == nil then return f:expandTemplate{title='Grid/Turning Table', args=gridArgs} end
	
	gridArgs.Type = string.sub(mw.text.split(args.Output,"%s* %s*")[1],2,-1)
	local valid = {Wooden=true, Iron=true}
	if valid[gridArgs.Type] == nil then
		--Someone's done a boo boo.
		return f:expandTemplate{title='Grid/Turning Table', args=gridArgs}
	end
	if gridArgs.Type == 'Wooden' then
			local bounce = 3
		else
			local bounce = 5
	end
	if args.Layout:find(',') then
		local layout = mw.text.split(args.Layout,"%g*,%g*")
		gridArgs.n1 = p.turningNumber(layout[0])
		gridArgs.n2 = p.turningNumber(layout[1])
		gridArgs.n3 = p.turningNumber(layout[2] or bounce)
		gridArgs.n4 = p.turningNumber(layout[3] or bounce)
		gridArgs.n5 = p.turningNumber(layout[4] or bounce)
	else
		bounce = p.turningNumber(bounce)
		gridArgs.n1 = bounce
		gridArgs.n2 = bounce
		gridArgs.n3 = bounce
		gridArgs.n4 = bounce
		gridArgs.n5 = bounce
	end
	
	return f:expandTemplate{title='Grid/Turning Table', args=gridArgs}
end
 
return p
--</syntaxhighlight>