Module:Recipe
Jump to navigation
Jump to search
-- thanks coral island wiki for this module!
local p = {}
local lib = require('Module:Feature')
local Icon = require('Module:Icon')._main
local category = mw.html.create()
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
return p._main(args)
end
function p._main(args)
local ingredients = args.ingredients or args[2]
assert(ingredients, 'No ingredients given')
local yield_item = args.product or mw.title.getCurrentTitle().rootText
local yield_image = args.product_image or yield_item
local yield_amount = args['yield'] or '1'
local workbench = args.workbench or args[3] or 'Menu'
local delim = args.delim or ';'
local delim_amount = args.delim_amount or '*'
local delim_quality = args.delim_quality or '/'
local workbench_time = args['time']
local recipesource = args['recipesource']
--start out and figure out cols
local out = mw.html.create('div'):addClass('sh-recipe-wrapper')
local data = {
ingredients = ingredients,
delim = delim,
amount = '^(.-)' .. delim_amount .. '(.*)$',
quality = '^(.-)' .. delim_quality .. '(.*)$',
}
out:tag('div'):addClass('sh-recipe-ingredient'):node(p.parseIngredients(data))
local out2 = out:tag('div'):addClass('sh-recipe-wrapper-second')
local workbench_div = out2:tag('div'):addClass('sh-recipe-workbench' .. lib.ternary(workbench_time~=nil, ' sh-recipe-timed', ''))
workbench_div:node(Icon{
name = workbench,
notext = 1,
size = 60,
})
workbench_div:tag('br')
workbench_div:wikitext('[[', workbench, ']]')
category:wikitext('[[Category:Crafted at ', string.lower(workbench), ']]')
--if lib.inArray({
-- 'bakers station',
-- 'cooking pot',
-- 'elven juicer',
-- 'fish grill',
-- 'ice cream cart',
-- 'juicer',
-- 'keg',
-- 'monster juicer',
-- 'monster sushi table',
-- 'oven',
-- 'sushi table',
-- 'tea kettle',
-- }, string.lower(workbench))
-- then category:wikitext('[[Category:Cooked dishes|', string.lower(workbench), ']]') end
if recipesource then
for source in lib.gsplit(string.lower(recipesource), ';') do
category:wikitext('[[Category:Recipe source is ', source, ']]')
end
end
if workbench_time then
workbench_div:tag('br')
workbench_div:tag('div'):addClass('sh-recipe-yield-amount'):tag('small'):wikitext(workbench_time)
end
out2
:tag('div')
:addClass('sh-recipe-yield')
:tag('div')
:addClass('sh-recipe-yield-img')
:node(Icon{
name = yield_image,
notext = 1,
size = 70,
})
:tag('div')
:addClass('sh-recipe-yield-amount')
:tag('small'):wikitext('×', yield_amount)
category:wikitext('[[Category:Crafted items]]')
out:node(require('Module:Namespace detect').main{main=category})
return out
end
local function makeIcon(str, data)
if not str then return mw.hmtl.create() end
local pre, quality = string.match(str, data.quality)
if not pre then
pre = str
end
local name, amount = string.match(pre, data.amount)
if not name then
name = pre
amount = '1'
end
category:wikitext('[[Category:Uses ', string.lower(name), ']]')
return Icon
{
name = name,
amount = amount,
size = '20',
quality = quality
}
end
function p.parseIngredients(data)
local list = mw.html.create()
for item in lib.gsplit(data.ingredients, ';') do
if lib.isNotEmpty(item) then
if item:find('//') then
for n, sub_item in ipairs(lib.split(item, '//')) do
if n>1 then list:tag('i'):wikitext(' or ') end
list:node(makeIcon(sub_item, data))
end
else
list:node(makeIcon(item, data))
end
end
end
return list
end
return p