Difference between revisions of "Module:HexoriumGenerator"
From CelesTek Wiki
(Created page with "local p = {} function p.table( f ) local args = f if f == mw.getCurrentFrame() then args = f:getParent().args else f = mw.getCurrentFrame() end local grid = require(...") |
(No difference)
|
Latest revision as of 18:58, 21 May 2015
Documentation for this module may be created at Module:HexoriumGenerator/doc
local p = {} function p.table( f ) local args = f if f == mw.getCurrentFrame() then args = f:getParent().args else f = mw.getCurrentFrame() end local grid = require( 'Module:Grid' ) -- Start table when appropriate local multirow = f:callParserFunction( '#dplvar', 'multirow' ) if multirow ~= '1' then multirow = nil end local head = args.head or '' if multirow then head = '' elseif head ~= '' then multirow = 1 f:callParserFunction( '#dplvar:set', 'multirow', '1' ) else head = 1 end -- End table when appropriate local foot = args.foot or '' if multirow then if foot ~= '' then multirow = nil f:callParserFunction( '#dplvar:set', 'multirow', '0' ) end else foot = 1 end local header = '' if head ~= '' then local name = '' local description = '' if args.showname == '1' or multirow and args.showname ~= '0' then name = 'Name !! ' f:callParserFunction( '#dplvar:set', 'hexoriumgeneratorname', '1' ) end if args.showdescription == '1' then description = ' !! class="unsortable" | Description' f:callParserFunction( '#dplvar:set', 'hexoriumgeneratordescription', '1' ) end local class = args.class or '' local recipeClass = '' if multirow then class = 'sortable collapsible ' .. class recipeClass = 'class="unsortable collapse-button" |' end header = table.concat( { ' {| class="wikitable ' .. '"', '! ' .. name .. 'Ingredients !! ' .. ' [[Hexorium Generator]] recipe' .. description, '|-' }, '\n' ) end local input = mw.text.trim( args[1] or '' ) local output = mw.text.trim( args[2] or '' ) -- Name cell local nameCell if args.name or '' ~= '' then nameCell = args.name elseif multirow or f:callParserFunction( '#dplvar', 'hexoriumgeneratorname' ) == '1' then local names = {} local links = {} for v in mw.text.gsplit( args[2] or '', '%s*;%s*' ) do parts = grid.getParts( v ) if not names[( parts.mod or '' ) .. parts.name] then local link = '' if parts.mod then link = 'Mods/' .. parts.mod .. '/' .. parts.name .. '|' end if parts.name:find( '^Any ' ) then table.insert( links, 'Any [[' .. link .. parts.name:sub( 4 ) .. ']]' ) else table.insert( links, '[[' .. link .. parts.name .. ']]' ) end names[( parts.mod or '' ) .. parts.name] = 1 end end nameCell = table.concat( links, ' or<br>' ) end if nameCell and args.upcoming then nameCell = nameCell .. '<br>([[' .. args.upcoming .. ']])' end -- Ingredients cell local ingredientsCell if args.ingredients or '' ~= '' then ingredientsCell = args.ingredients end -- Any args we want to pass along local newArgs = { Input = args[1], Output = args[2], Ititle = args.Ititle, Otitle = args.Otitle, Ftitle = args.Ftitle } -- Recipe cell local recipeCell = grid.hexoriumGenerator( newArgs ) local row = { ingredientsCell, recipeCell } if nameCell then table.insert( row, 1, nameCell ) end if f:callParserFunction( '#dplvar', 'hexoriumgeneratordescription' ) == '1' then table.insert( row, args.description or '' ) end row = table.concat( row, '\n|\n' ) if nameCell then row = '!\n' .. row else row = '|\n' .. row end local footer = '' if foot ~= '' then footer = '|}' f:callParserFunction( '#dplvar:set', 'hexoriumgeneratorname', '0', 'hexoriumgeneratordescription', '0' ) end local title = mw.title.getCurrentTitle() local category = '' if args.upcoming and args.nocat ~= '1' and title.namespace == 0 and not title.isSubpage then category = '[[Category:Upcoming]]' end return header .. '\n' .. row .. '\n|-\n' .. footer .. category end return p