Módulo:Crafts/ingredient

Fonte: Terraria Wiki
Saltar para a navegação Saltar para a pesquisa

Internal sub-module pertaining to the set of {{crafts}}.

Normalizes an ingredients input and outputs it in a properly formatted way.


local metals = {
	['Copper/Tin'] = 1,
	['Silver/Tungsten'] = 1,
	['Gold/Platinum'] = 1,
	['Iron/Lead'] = 1,
	['Cobalt/Palladium'] = 1,
	['Mythril/Orichalcum'] = 1,
	['Adamantite/Titanium'] = 1,
	['Tin/Copper'] = 2,
	['Tungsten/Silver'] = 2,
	['Platinum/Gold'] = 2,
	['Lead/Iron'] = 2,
	['Palladium/Cobalt'] = 2,
	['Orichalcum/Mythril'] = 2,
	['Titanium/Adamantite'] = 2,
}

local function split(name)
	local item1a, item1b, item2a, item2b = name:match("^(%S+)%s*(.-)/(%S+)%s*(.-)$")
	if item1a then
		local x = metals[item1a..'/'..item2a]
		if tostring(item1b) == '' and x then
			item1b = item2b
		end
		if x == 2 then
			return item2a..' '..item2b, item1a..' '..item1b
		else
			return item1a..' '..item1b, item2a..' '..item2b
		end
	else
		return name
	end
end

-- main return object 
return {
go = function(frame)
	
	local _input = mw.text.trim(frame.args[1])
	local _basepage = mw.text.trim(frame.args[2])

	local icons

	local result = ''
	for name, amount in _input:gmatch("(.-)¦(.-)¶") do
		local li = ''
		item1, item2 = split(name)
		if item2 then
			if item1 == _basepage then icons = 'no' else icons = '' end
			li = li .. frame:expandTemplate{ title = 'item', args = {item1, icons=icons } }
			li = li .. " ''or'' " 
			if item2 == _basepage then icons = 'no' else icons = '' end
			li = li .. frame:expandTemplate{ title = 'item', args = {item2, icons=icons } }
		else 
			if name == _basepage then icons = 'no' else icons = '' end
			li = li .. frame:expandTemplate{ title = 'item', args = {name, icons=icons } }
		end
		result = result .. mw.text.tag('li', nil, li .. amount)
	end
	return mw.text.tag('ul', nil, result)

end
}