Module:Metallurgic Infuser: Difference between revisions

mNo edit summary
No edit summary
Line 89: Line 89:
end
end
end
end
-- Infusion materials
local infusionMaterial = {
['Diamond'] = 'Diamond Dust; Compressed Diamond',
['Obsidian'] = 'Refined Obsidian Dust; Compressed Obsidian',
['Tin'] = 'Tin Dust',
['Bio Fuel'] = 'Bio Fuel',
['Redstone'] = 'Redstone; Block of Redstone; Compressed Redstone',
['Carbon'] = 'Coal; Charcoal; Compressed Carbon',
['Mushroom'] = '[Mushroom]Red Mushroom; [Mushroom]Brown Mushroom'
}


-- Create ingredient list
-- Create ingredient list
Line 97: Line 108:
for k, v in pairs( args ) do
for k, v in pairs( args ) do
v = mw.text.trim( v )
v = mw.text.trim( v )
if v ~= '' and (tostring( k ):find( '^Infuse$' ) or tostring( k ):find( '^Input$' )) then
if v ~= '' then
if v:find( ';' ) then
if tostring( k ):find( '^Input$' ) then
table.insert( animatedKeys, v )
if v:find( ';' ) then
else
table.insert( animatedKeys, v )
local parts = grid.getParts( v, args.Mod )
else
parts.mod = parts.mod or ''
local parts = grid.getParts( v, args.Mod )
local fullName = parts.mod .. ':' .. parts.name
parts.mod = parts.mod or ''
if not ingredients[fullName] then
local fullName = parts.mod .. ':' .. parts.name
table.insert( ingredientKeys, fullName )
if not ingredients[fullName] then
ingredients[fullName] = { mod = parts.mod, name = parts.name }
table.insert( ingredientKeys, fullName )
ingredients[fullName] = { mod = parts.mod, name = parts.name }
end
end
end
elseif tostring( k ):find( '^Infuse$' ) then
table.insert( animatedKeys, infusionMaterial[v] )
end
end
end
end

Revision as of 06:31, 22 July 2015

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

local p = {}
function p.table( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'Module:ProcessArgs' ).merge()
	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', 'craftingname', '1' )
		end
		if args.showdescription == '1' then
			description = ' !! class="unsortable" | Description'
			f:callParserFunction( '#dplvar:set', 'craftingdescription', '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 ' .. class .. '"',
			'! ' .. name .. 'Ingredients !! ' .. recipeClass .. ' [[Metallurgic Infuser]] recipe' .. description,
			'|-'
		}, '\n' )
	end
	
	-- Name cell
	local nameCell
	if f:callParserFunction( '#dplvar', 'craftingname' ) == '1' then
		if args.name or '' ~= '' then
			nameCell = args.name
		else
			local names = {}
			local links = {}
			for v in mw.text.gsplit( args.Output or '', '%s*;%s*' ) do
				parts = grid.getParts( v, args.Mod )
				parts.mod = parts.mod or ''
				if not names[parts.mod .. ':' .. 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 .. ':' .. parts.name] = 1
				end
			end
			
			nameCell = table.concat( links, '&nbsp;or<br>' )
		end
	end

	-- Infusion materials
	local infusionMaterial = {
		['Diamond'] = 'Diamond Dust; Compressed Diamond',
		['Obsidian'] = 'Refined Obsidian Dust; Compressed Obsidian',
		['Tin'] = 'Tin Dust',
		['Bio Fuel'] = 'Bio Fuel',
		['Redstone'] = 'Redstone; Block of Redstone; Compressed Redstone',
		['Carbon'] = 'Coal; Charcoal; Compressed Carbon',
		['Mushroom'] = '[Mushroom]Red Mushroom; [Mushroom]Brown Mushroom'
	}

	-- Create ingredient list
	local ingredients = {}
	local ingredientKeys = {}
	local animatedIngredients = {}
	local animatedKeys = {}
	for k, v in pairs( args ) do
		v = mw.text.trim( v )
		if v ~= '' then
			if tostring( k ):find( '^Input$' ) then
				if v:find( ';' ) then
					table.insert( animatedKeys, v )
				else
					local parts = grid.getParts( v, args.Mod )
					parts.mod = parts.mod or ''
					local fullName = parts.mod .. ':' .. parts.name
					if not ingredients[fullName] then
						table.insert( ingredientKeys, fullName )
						ingredients[fullName] = { mod = parts.mod, name = parts.name }
					end
				end
			elseif tostring( k ):find( '^Infuse$' ) then
				table.insert( animatedKeys, infusionMaterial[v] )
			end
		end
	end
	for k, v in ipairs( animatedKeys ) do
		local frames = mw.text.split( v, '%s*;%s*' )
		local length = #frames
		for k2, v2 in ipairs( frames ) do
			local parts = grid.getParts( v2, args.Mod )
			parts.mod = parts.mod or ''
			local fullName = parts.mod .. ':' .. parts.name
			if v2 ~= '' and not ingredients[fullName] and not animatedIngredients[fullName] then
				table.insert( ingredientKeys, fullName )
				animatedIngredients[fullName] = { mod = parts.mod, name = parts.name, final = k2 == length }
			end
		end
	end
	
	-- Ingredients cell
	local ingredientsCell
	if args.ingredients or '' ~= '' then
		ingredientsCell = args.ingredients
	else
		ingredientsCell = {}
		for k, v in ipairs( ingredientKeys ) do
			local link = ''
			local separator = '&nbsp;+'
			if k == #ingredientKeys then
				separator = ''
			elseif animatedIngredients[v] and not animatedIngredients[v].final then
				separator = '&nbsp;or'
			end
			local mod = ( ingredients[v] or animatedIngredients[v] ).mod
			local name = ( ingredients[v] or animatedIngredients[v] ).name
			if mod ~= '' then
				link = 'Mods/'.. mod .. '/' .. name .. '|'
			end
			
			if name:find( '^Any ' ) then
				table.insert( ingredientsCell, 'Any [[' .. link .. name:sub( 5 ) .. ']]' .. separator )
			else
				table.insert( ingredientsCell, '[[' .. link .. name .. ']]' .. separator )
			end
		end
		
		ingredientsCell = table.concat( ingredientsCell, '<br>\n' )
	end

	-- Recipe cell
	local recipeCell = grid.metallurgicInfuser( args )
	
	local row = { ingredientsCell, recipeCell }
	if nameCell then
		table.insert( row, 1, nameCell )
	end
	if f:callParserFunction( '#dplvar', 'craftingdescription' ) == '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', 'craftingname', '0', 'craftingdescription', '0' )
	end
	
	-- Create ingredient categories for DPL
	local title = mw.title.getCurrentTitle()
	local categories = ''
	if args.nocat ~= '1' and title.namespace == 0 and not title.isSubpage then
		categories = {}

		if args.type then
			table.insert( categories, '[[Category:' .. args.type .. ' recipe]]' )
		end
		
		if args.ignoreusage ~= '1' then
			for k, v in ipairs( ingredientKeys ) do
				v = v:sub( 2 )
				if not v:find( ':' ) then
					table.insert( categories, '[[Category:Recipe using ' .. v .. ']]' )
				end
			end
		end
		
		categories = table.concat( categories, '' )
	end
	
	if args.debug == '1' then
		return '<pre>' .. header .. '\n' .. row .. '\n|-\n' .. footer .. categories .. '</pre>'
	else
		return header .. '\n' .. row .. '\n|-\n' .. footer .. categories
	end
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