Module:Recipe list

From TibiaCraft
Jump to navigationJump to search

This module is used to list all recipes in a particular category.

The type function will match recipes which have the type parameter set to the same value as the input.

Example

{{#invoke:recipe list|type|Foodstuff}}, lists all recipes with type set to Foodstuff.




local p = {}
function p.type( f )
	local args = f.args
	local crafting = require( [[Module:Crafting]] ).table
	local type = mw.text.trim( args[1] )
	
	local showDesciption
	local templates = {}
	
	local data = bucket('crafting_recipe')
					.select('type', 'json')
					.where('type', type)
					.run()

	for _, v in ipairs(data) do
		local tArgs = mw.text.jsonDecode(v['json'])
		if tArgs.description then
			showDescription = true
		end
		
		tArgs.ignoreusage = '1'
		
		table.insert( templates, tArgs )
	end
	
	if #templates == 0 then
		return
	end
	
	templates[1].head = '1'
	templates[1].showname = '1'
	if showDescription and args.showdesciption ~= '0' or args.showdesciption == '1' then
		templates[1].showdescription = '1'
	end
	if not args.continue then
		templates[#templates].foot = '1'
	end
	
	local out = {}
	for i, v in ipairs( templates ) do
		table.insert( out, crafting( v ) )
	end
	
	return table.concat( out, '\n' )
end
return p