Модуль:Meals Lookup: различия между версиями

Нет описания правки
Нет описания правки
Строка 5: Строка 5:
p.meals = prototypes.meals
p.meals = prototypes.meals


 
--#region universal
function getrecipesfromtype(frame, type) -- {{#invoke:Meals Lookup|getrecipesfromtype|ProtoID}}
function getrecipesfromtype(frame, type) -- should not be invoked
     return p.meals[type]
     return p.meals[type]
end
end
Строка 14: Строка 14:
end
end


function getrecipetypes(frame, id) -- should not be invoked
    local out = {}
    for type, recipes in pairs(p.meals) do
        for recipeId, recipe in pairs(recipes) do
            if (recipeId:gsub(' ', '') == id:gsub(' ', '')) or (recipe["id"]:gsub(' ', '') == id:gsub(' ', '')) then
                table.insert(out, type)
                break
            end
        end
    end
    return out
end
--#endregion
--#region microwaveRecipes
function getmicrowaverecipesolids(frame, recipe) -- should not be invoked
function getmicrowaverecipesolids(frame, recipe) -- should not be invoked
     local out = {}
     local out = {}
Строка 38: Строка 53:
end
end


function p.buildreagents(frame, array)
function buildreagents(frame, array) -- should not be invoked
     local out = ""
     local out = ""
     for item, amount in pairs(array) do
     for item, amount in pairs(array) do
Строка 47: Строка 62:
end
end


function p.buildmicrowaverecipebox(frame)
function p.buildmicrowaverecipebox(frame) -- {{#invoke:Meals Lookup|buildmicrowaverecipebox|MicrowaveRecipeID}}
     local out = "hehe"
     local out = ""
     local id = frame.args[1]:gsub(' ', '')
     local id = frame.args[1]:gsub(' ', '')
     local recipe = getrecipe(frame, "microwaveRecipes", id)
     local recipe = getrecipe(frame, "microwaveRecipes", id)
     local solids = buildsolids(frame, getmicrowaverecipesolids(frame, recipe))
     local solids = buildsolids(frame, getmicrowaverecipesolids(frame, recipe))
     local reagents = p.buildreagents(frame, getmicrowaverecipereagents(frame, recipe))
     local reagents = buildreagents(frame, getmicrowaverecipereagents(frame, recipe))
     out = frame:preprocess("{{Recipe Box"..
     out = frame:preprocess("{{Recipe Box"..
     "|name={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}"..
     "|name={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}"..
Строка 61: Строка 76:
     return out
     return out
end
end
--#endregion microwaveRecipes
--#region sliceableRecipes


-- returns all types for a recipe with given id, should not be used out of module
function p.buildmslicerecipebox(frame) -- {{#invoke:Meals Lookup|buildmslicerecipebox|SliceableRecipeID}}
function p.getrecipetypes(frame, id)
     local out = ""
     local out = {}
     local id = frame.args[1]:gsub(' ', '')
     for type, recipes in pairs(p.meals) do
    local recipe = getrecipe(frame, "sliceableRecipes", id)
        for recipeId, recipe in pairs(recipes) do
    out = frame:preprocess("{{Recipe Box"..
            if (recipeId:gsub(' ', '') == id:gsub(' ', '')) or (recipe["id"]:gsub(' ', '') == id:gsub(' ', '')) then
    "|name={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}"..
                table.insert(out, type)
    "|component-1="..frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|".. recipe["input"] .."}}|image=Файл:Mousegif.gif}}" ) ..
                break
    "|transformer={{Recipe Transformers|sliceableRecipes}}"..
            end
    "|result=".. frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}|image=Файл:Mousegif.gif|amount="..recipe["count"].."}}" ) ..
        end
     "}}")
     end
     return out
     return out
end
end
--#endregion sliceableRecipes


-- tests.
-- tests.
function p.tests(frame)
function p.tests(frame)
     local out = ""
     local out = ""
    out = out .. buildsolids(frame, getmicrowaverecipesolids(frame, getrecipe(frame, frame.args[2], frame.args[1])))
    out = out .. "\n" .. p.buildreagents(frame, getmicrowaverecipereagents(frame, getrecipe(frame, frame.args[2], frame.args[1])))
     out = out .. "\n" .. frame:preprocess("{{#invoke:Meals Lookup|buildmicrowaverecipebox|".. frame.args[1] .. "}}")
     out = out .. "\n" .. frame:preprocess("{{#invoke:Meals Lookup|buildmicrowaverecipebox|".. frame.args[1] .. "}}")
    out = out .. "\n" .. frame:preprocess("{{#invoke:Meals Lookup|buildmslicerecipebox|".. frame.args[2] .. "}}")
     -- out = out .. p.buildmicrowaverecipebox(frame, frame.args[1])
     -- out = out .. p.buildmicrowaverecipebox(frame, frame.args[1])
     return out
     return out