Модуль:Meals Lookup: различия между версиями
Mhamster (обсуждение | вклад) Нет описания правки |
Mhamster (обсуждение | вклад) молитвы на работу кода скачать онлайн |
||
| Строка 1: | Строка 1: | ||
local prototypes = mw.loadData("Module:Meals Lookup/data") | local prototypes = mw.loadData("Module:Meals Lookup/data") | ||
local e = require("Module:Entity_Lookup") | |||
local p = {} | local p = {} | ||
| Строка 5: | Строка 6: | ||
function p.getrecipesfromtype(frame) -- {{#invoke:Meals Lookup|getrecipesfromtype|ProtoID}} | function p.getrecipesfromtype(frame, type) -- {{#invoke:Meals Lookup|getrecipesfromtype|ProtoID}} | ||
local out = "" | return p.meals[type] | ||
end | |||
function p.getrecipe(frame, type, id) | |||
return p.getrecipesfromtype(frame, type)[id] | |||
end | |||
function p.getmicrowaverecipesolids(frame, recipe) | |||
local out = {} | |||
for ingredient, amount in pairs(recipe["solids"]) do | |||
table.insert(out, ingredient, amount) | |||
end | |||
return out | |||
end | |||
return out | function p.getmicrowaverecipereagents(frame, recipe) | ||
local out = {} | |||
for ingredient, amount in pairs(recipe["reagents"]) do | |||
table.insert(out, ingredient, amount) | |||
end | |||
return out | |||
end | end | ||
function p. | function p.buildmicrowaverecipebox(frame, recipeId) | ||
local out = "" | local out = "" | ||
return out | local id = "" | ||
if frame.args["id"] ~= nil then id = frame.args["id"] | |||
else id = recipeId end | |||
local recipe = p.getrecipe(frame, "microwaveRecipes", id) | |||
local solids = "" | |||
local reagents = "" | |||
for solidId, amount in pairs(p.getmicrowaverecipesolids(frame, recipe)) do | |||
solids = solids .. frame.expandTemplate{ title = "Recipe Component", item = e.getname(frame, solidId), amount = amount} | |||
end | |||
for reagentId, amount in pairs(p.getmicrowaverecipereagents(frame, recipe)) do | |||
reagents = reagents .. frame.expandTemplate{ title = "Recipe Component", item = e.getname(frame, reagentId), amount = amount} | |||
end | |||
return out | |||
end | end | ||
function p. | -- returns all types for a recipe with given id, should not be used out of module | ||
local out = { } | function p.getrecipetypes(frame, id) | ||
local out = {} | |||
for type, recipes in pairs(p.meals) do | for type, recipes in pairs(p.meals) do | ||
for recipeId, recipe in pairs(recipes) do | for recipeId, recipe in pairs(recipes) do | ||
| Строка 26: | Строка 58: | ||
end | end | ||
end | end | ||
return out | return out | ||
end | end | ||
-- tests. | |||
function p.tests(frame) | function p.tests(frame) | ||
local out = "" | local out = "" | ||
out = | out = out .. p.buildmicrowaverecipebox(frame, frame.args[1]) | ||
return out | |||
return out | |||
end | end | ||
return p | return p | ||