Module:Grid
From TerraFirmaCraft Wiki
Revision as of 22:11, 8 September 2013 by Kittychanley (Talk | contribs) (Created page with "local p = {} -- Individual cell function p.cell( f ) local args = f.args or f if args[1] == nil then args = f:getParent().args end ...")
local p = {}
-- Individual cell function p.cell( f )
local args = f.args or f if args[1] == nil then args = f:getParent().args end local title = args.title or local link = args.link or local alt if title ~= then link = 'none' if title:lower() ~= 'none' then alt = title end end args[1] = ( args[1] or ):gsub( '^%s*(.-)%s*$', '%1' ) local names = mw.text.split( args[1], '%s*;%s*' ) local animated = args[1]:find( ';' ) local pageName = mw.title.getCurrentTitle().subpageText local class = args.class or local imgClass = args.imgclass or local align = args.align or local cell = {} local translatron = mw.loadData( 'Module:Grid/Translatron' ); for i, name in ipairs( names ) do local active = if animated and i == 1 then active = ' active' end if name == then if animated then table.insert( cell, '
' ) else table.insert( cell, '
' ) end else local parts = mw.text.split( name, '%s*[:,]%s*' ) local mod = local fullName local img local num if name:find( ':' ) then if parts[1]:lower() ~= 'v' and parts[1]:lower() ~= 'vanilla' then mod = parts[1] end name = parts[2] num = math.floor( parts[3] or 0 ) else mod = args.mod or name = parts[1] num = math.floor( parts[2] or 0 ) end if mod ~= then fullName = name .. ' (' .. mod .. ')' else fullName = name end if translatron[fullName] then img = translatron[fullName] else img = fullName end local link = link if link == then if mod ~= then link = 'Mods/' .. mod .. '/' .. name else link = name end if name == pageName then link = 'none' end end local title = title if title == then if link:lower() == 'none' then title = fullName else title = end end local alt = alt or fullName if link:lower() == 'none' then link = end if title:lower() == 'none' then title = end local image = { '', 'title=' .. title .. '', '', } image[1] = image[1]:gsub( ' title=""', ) image[2] = image[2]:gsub( 'title=|', ) if num > 1 and num < 1000 then if link ~= then num = '' .. num .. '' end table.insert( image, 3, '' .. num .. '' ) end table.insert( cell, table.concat( image, ) ) end end if animated then table.insert( cell, 1, '' ) table.insert( cell, '' ) end if align ~= then align = ' style="vertical-align:' .. align .. '"' end local html = { '', table.concat( cell, ), '' } if ( args.default or ) ~= then table.insert( html, 2, '32px' ) end html = table.concat( html, ):gsub( ' "', '"' ) return html
end
--- GUI variants; called directly to avoid the overhead of a bunch of #invoke calls per GUI -- Crafting table function p.craftingTable( f )
local args = f:getParent().args local arrow = 'Arrow (small)' local shapeless = if args.arrow then arrow = args.arrow .. ' (' .. args.mod .. ')' end if args.shapeless then shapeless = '' end local html = { '{| cellpadding="0" cellspacing="0" class="grid-Crafting_Table"', '| ' .. p.cell( { args.A1, mod = args.mod, link = args.A1link, title = args.A1title } ), '| ' .. p.cell( { args.B1, mod = args.mod, link = args.B1link, title = args.B1title } ), '| ' .. p.cell( { args.C1, mod = args.mod, link = args.C1link, title = args.C1title } ), '| rowspan="2" class="arrow" | File:Grid layout ' .. arrow .. '.png', '| rowspan="3" | ' .. p.cell( { args.Output, mod = args.mod, link = args.Olink, title = args.Otitle, class = 'output' } ), '|-', '| ' .. p.cell( { args.A2, mod = args.mod, link = args.A2link, title = args.A2title } ), '| ' .. p.cell( { args.B2, mod = args.mod, link = args.B2link, title = args.B2title } ), '| ' .. p.cell( { args.C2, mod = args.mod, link = args.C2link, title = args.C2title } ), '|-', '| ' .. p.cell( { args.A3, mod = args.mod, link = args.A3link, title = args.A3title } ), '| ' .. p.cell( { args.B3, mod = args.mod, link = args.B3link, title = args.B3title } ), '| ' .. p.cell( { args.C3, mod = args.mod, link = args.C3link, title = args.C3title } ), '| class="shapeless" | ' .. shapeless, '|}' } return table.concat( html, '\n' );
end
-- Furnace function p.furnace( f )
local args = f:getParent().args local progress = 'Furnace Progress' local burning = ' (in-active)' local smelting = burning local fuelUsage = 'Fire' if args.Progress ~= then progress = args.Progress .. ' Progress (' .. args.mod .. ')' end
if args.Input ~= and args.Fuel ~= then burning = if args.Output ~= then smelting = end end if args.FuelUsage ~= then fuelUsage = args.FuelUsage .. ' (' .. args.mod .. ')' end local html = { '{| cellpadding="0" cellspacing="0" class="grid-Furnace"', '| ' .. p.cell( { args.Input, mod = args.mod, link = args.Ilink, title = args.Ititle } ), '| rowspan="3" class="arrow" | File:Grid layout ' .. progress .. smelting .. '.png', '| rowspan="3" class="output" | ' .. p.cell( { args.Output, mod = args.mod, link = args.Olink, title = args.Otitle, class = 'output' } ), '|-', '| File:Grid layout ' .. fuelUsage .. burning .. '.png', '|-', '| ' .. p.cell( { args.Fuel, mod = args.mod, link = args.Flink, title = args.Ftitle } ), '|}' } return table.concat( html, '\n' );
end
-- Brewing Stand function p.brewingStand( f )
local args = f:getParent().args local inactive = ' (In-active)' if args.Input ~= and ( args.Output1 ~= or args.Output2 ~= or args.Output3 ~= ) then inactive = end local html = {'
',
'
'{| cellpadding="0" cellspacing="0"', '| class="bubbles" | File:Grid layout Brewing Bubbles' .. inactive .. '.gif', '| class="input" | ' .. p.cell( { args.Input, mod = args.mod, link = args.Ilink, title = args.Ititle } ), '| File:Grid layout Brewing Arrow' .. inactive .. '.png', '|-', '| class="output1" | ' .. p.cell( { args.Output1, mod = args.mod, link = args.O1link, title = args.O1title, default = 'layout Brewing Empty' } ), '| class="output2" | ' .. p.cell( { args.Output2, mod = args.mod, link = args.O2link, title = args.O2title, default = 'layout Brewing Empty' } ), '| class="output3" | ' .. p.cell( { args.Output3, mod = args.mod, link = args.O3link, title = args.O3title, default = 'layout Brewing Empty' } ), '|-', '| class="paths" colspan="3" | File:Grid layout Brewing Paths.png', '|}','
} return table.concat( html, '\n' );
end
return p