Module:Recipe: Difference between revisions
SlyAceZeta (talk | contribs) (adding check for items crafted as part of other recipes) |
SlyAceZeta (talk | contribs) (assigning argument to a variable to hopefully parse the page name by default; adding hopefully-working basic recipe output) |
||
Line 5: | Line 5: | ||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
local prod |
|||
if args[1] then |
if args[1] then |
||
prod = args[1] |
|||
⚫ | |||
⚫ | |||
-- prod = pageName |
|||
⚫ | |||
end |
|||
if data[prod] then |
|||
⚫ | |||
⚫ | |||
else |
|||
if data[prod].recipe then |
|||
for key,value in next,data[prod].recipe do |
|||
print(key,value) |
|||
end |
|||
else |
else |
||
error ("'" .. prod .. "' is not crafted; use Template:Uses instead") |
|||
return data[args[1]].name |
|||
end |
end |
||
⚫ | |||
⚫ | |||
end |
end |
||
else |
|||
⚫ | |||
end |
end |
||
end |
end |
Revision as of 22:32, 8 June 2022
This module standardizes the display of crafting recipes and makes it easy to display a specified item's recipe or all recipes that use a specified ingredient. See Template:RecipeNew for more information. Thanks to BryghtShadow for helping out with the loops!
local p = {}
local data = mw.loadData('Module:Recipe/data')
local getArgs = require('Dev:Arguments').getArgs
function p.main(frame)
local args = getArgs(frame)
local prod
if args[1] then
prod = args[1]
else
-- prod = pageName
end
if data[prod] then
if data[prod].original then
error ("'" .. prod .. "' is not crafted standalone; use '" .. data[prod].original .. "' instead")
else
if data[prod].recipe then
for key,value in next,data[prod].recipe do
print(key,value)
end
else
error ("'" .. prod .. "' is not crafted; use Template:Uses instead")
end
end
else
error ("'" .. prod .. "' recipe does not exist")
end
end
return p