Warning.png

Поддержка Wiki прекращена, она доступна в режиме архива. Информация в ней устарела и может быть неактуальной.

Модуль:Smelting — различия между версиями

Материал из Hilarious Wiki
Перейти к: навигация, поиск
 
(не показаны 4 промежуточные версии этого же участника)
Строка 88: Строка 88:
 
end
 
end
 
 
 +
 
-- Name cell
 
-- Name cell
 
local nameCell
 
local nameCell
if f:callParserFunction( '#dplvar', 'craftingname' ) == '1' then
+
if args.name or '' ~= '' then
if args.name or '' ~= '' then
+
nameCell = args.name
nameCell = args.name
+
elseif multirow or f:callParserFunction( '#dplvar', 'smeltingname' ) == '1' then
else
+
local names = {}
local names = {}
+
local links = {}
local links = {}
+
for v in mw.text.gsplit( args[2] or '', '%s*;%s*' ) do
for v in mw.text.gsplit( args.Output or '', '%s*;%s*' ) do
+
parts = getParts( v, args.Mod )
parts = getParts( v, args.Mod )
+
if not names[( parts.mod or '' ) .. parts.name] then
parts.mod = parts.mod or ''
+
local link = ''
if not names[parts.mod .. ':' .. parts.name] then
+
if parts.mod then
table.insert( links, prefixedLink( parts.name, parts.mod ) )
+
link = 'Mods/' .. parts.mod .. '/' .. parts.name .. '|'
names[parts.mod .. ':' .. parts.name] = 1
 
 
end
 
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, '&nbsp;or<br>' )
 
 
end
 
end
 +
 +
nameCell = table.concat( links, '&nbsp;or<br>' )
 
end
 
end
+
 
 
if nameCell and args.upcoming then
 
if nameCell and args.upcoming then
 
nameCell = nameCell .. '<br>([[' .. args.upcoming .. ']])'
 
nameCell = nameCell .. '<br>([[' .. args.upcoming .. ']])'
Строка 126: Строка 133:
 
end
 
end
 
for item in mw.text.gsplit( v, '%s*;%s*' ) do
 
for item in mw.text.gsplit( v, '%s*;%s*' ) do
local parts = getParts( item )
+
local parts = getParts( item, args.Mod )
 
if parts.name ~= '' and not ingredients[parts.name] and ( k == 2 or k == 1 and v ~= fuel ) then
 
if parts.name ~= '' and not ingredients[parts.name] and ( k == 2 or k == 1 and v ~= fuel ) then
 
local link = ''
 
local link = ''
Строка 160: Строка 167:
 
Otitle = args.Otitle,
 
Otitle = args.Otitle,
 
Ftitle = args.Ftitle,
 
Ftitle = args.Ftitle,
         Mod = args.Mod
+
         Mod = args.Mod,
 +
        Progress = args.Progress
 
}
 
}
+
 
 
-- Recipe cell
 
-- Recipe cell
 
local recipeCell = require( 'Module:UI' ).furnace( newArgs )
 
local recipeCell = require( 'Module:UI' ).furnace( newArgs )

Текущая версия на 09:40, 15 августа 2016

Для документации этого модуля может быть создана страница Модуль:Smelting/док

local p = {}
local slot = require( [[Module:Inventory slot]] )
local getParts = slot.getParts
local prefixes = slot.prefixes

local function prefixedLink( name, mod )
	local prefix = ''
	for _, thisPrefix in pairs( prefixes ) do
		if name:find( '^' .. thisPrefix .. ' ' ) then
			prefix = thisPrefix .. ' '
			name = name:gsub( '^' .. prefix, '' )
			break
		end
	end
	
	local page = ''
	if mod and mod ~= '' then
		page = 'Mods/' .. mod .. '/'
	end
	
	return prefix .. '[[' .. page .. name .. '|' .. name .. ']]'
end

function p.table( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	
	-- 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', 'smeltingname', '1' )
		end
		if args.showdescription == '1' then
			description = ' !! class="unsortable" | Description'
			f:callParserFunction( '#dplvar:set', 'smeltingdescription', '1' )
		end
		local class = args.class or ''
		local recipeClass = ''
		if multirow then
			class = 'sortable collapsible ' .. class
			recipeClass = 'class="unsortable" |'
		end
		header = table.concat( {
			' {| class="wikitable ' .. class .. '" data-description="Smelting recipes"',
			'! ' .. name .. 'Ingredients !! ' .. recipeClass .. ' [[Smelting]] recipe' .. description,
			'|-'
		}, '\n' )
	end
	
	local input = mw.text.trim( args[1] or '' )
	local output = mw.text.trim( args[2] or '' )
	local fuel = args.fuel or ''
	if fuel == '' then
		fuel = 'Any fuel'
	end
	

	-- Name cell
	local nameCell
	if args.name or '' ~= '' then
		nameCell = args.name
	elseif multirow or f:callParserFunction( '#dplvar', 'smeltingname' ) == '1' then
		local names = {}
		local links = {}
		for v in mw.text.gsplit( args[2] or '', '%s*;%s*' ) do
			parts = getParts( v, args.Mod )
			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, '&nbsp;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
	else
		ingredientsCell = {}
		local ingredients = {}
		for k, v in ipairs{ input, fuel } do
			local separator = ''
			if k == 2 and next( ingredients ) then
				separator = '&nbsp;+<br>\n'
			end
			for item in mw.text.gsplit( v, '%s*;%s*' ) do
				local parts = getParts( item, args.Mod )
				if parts.name ~= '' and not ingredients[parts.name] and ( k == 2 or k == 1 and v ~= fuel ) then
					local link = ''
					if separator == '' and next( ingredients ) then
						separator = '&nbsp;or<br>\n'
					end
					
					if parts.mod then
						link = 'Mods/'.. parts.mod .. '/' .. parts.name .. '|'
					end
					
					if parts.name:find( '^Any ' ) then
						table.insert( ingredientsCell, separator .. 'Any [[' .. link .. parts.name:sub( 4 ) .. ']]' )
					else
						table.insert( ingredientsCell, separator .. '[[' .. link .. parts.name .. ']]' )
					end
					separator = ''
					
					ingredients[parts.name] = 1
				end
			end
		end
		
		ingredientsCell = table.concat( ingredientsCell )
	end
	
	-- Any args we want to pass along
	local newArgs = {
		Input = args[1],
		Output = args[2],
		Fuel = fuel,
		Ititle = args.Ititle,
		Otitle = args.Otitle,
		Ftitle = args.Ftitle,
        Mod = args.Mod,
        Progress = args.Progress
	}

	-- Recipe cell
	local recipeCell = require( 'Module:UI' ).furnace( newArgs )
	
	local row = {
		'\n' .. ingredientsCell,
		'style="padding:1px" |\n' .. recipeCell
	}
	if nameCell then
		table.insert( row, 1, nameCell )
	end
	if f:callParserFunction( '#dplvar', 'smeltingdescription' ) == '1' then
		table.insert( row, args.description or '' )
	end
	row = table.concat( row, '\n|' )
	
	if nameCell then
		row = '!\n' .. row
	else
		row = '|\n' .. row
	end
	
	local footer = ''
	if foot ~= '' then
		footer = '|}'
		f:callParserFunction( '#dplvar:set', 'smeltingname', '0', 'smeltingdescription', '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