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

Материал из Space Station 14 Вики
Нет описания правки
Нет описания правки
Строка 28: Строка 28:
         -- table.insert(out, ingredient, amount)
         -- table.insert(out, ingredient, amount)
         out[ingredient] = amount
         out[ingredient] = amount
    end
    return out
end
function p.buildsolids(frame, array)
    local out = ""
    for item, amount in pairs(array) do
        out = out .. frame:expandTemplate{ title = "Recipe Component", item = e.getname(frame, item), amount = amount}
    end
    return out
end
function p.buildreagents(frame, array)
    local out = ""
    for item, amount in pairs(array) do
        out = out .. frame:expandTemplate{ title = "Chem Recipe Component", reagent = item, amount = amount}
     end
     end
     return out
     return out
Строка 38: Строка 54:
     else id = recipeId end
     else id = recipeId end
     local recipe = p.getrecipe(frame, "microwaveRecipes", id)
     local recipe = p.getrecipe(frame, "microwaveRecipes", id)
     local solids = ""
     local solids = p.buildsolids(frame, p.getmicrowaverecipesolids(frame, recipe))
    local reagents = ""
    local reagents = p.buildreagents(frame, p.getmicrowaverecipereagents(frame, recipe))
    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 = "Chem Recipe Component", reagent = reagentId, amount = amount}
    end
     out = frame:expandTemplate{ title = "Recipe Box",  
     out = frame:expandTemplate{ title = "Recipe Box",  
     name = e.getname(frame, recipe["result"]),  
     name = e.getname(frame, recipe["result"]),  
     ["component-1"] = solids..reagents,  
     ["component-1"] = solids .. reagents,  
     transformer = frame:expandTemplate{title="Recipe Transformers", "microwaveRecipes", recipe["time"]},  
     transformer = frame:expandTemplate{title="Recipe Transformers", "microwaveRecipes", recipe["time"]},  
     result = frame:expandTemplate{ title = "Recipe Component", item = e.getname(frame, recipe["result"])}}
     result = frame:expandTemplate{ title = "Recipe Component", item = e.getname(frame, recipe["result"])}}
Строка 71: Строка 81:
function p.tests(frame)
function p.tests(frame)
     local out = ""
     local out = ""
     out = out .. p.buildmicrowaverecipebox(frame, frame.args[1])
     out = out .. p.buildsolids(frame, p.getrecipe(frame, frame.args[1], frame.args[2]))
    -- out = out .. p.buildmicrowaverecipebox(frame, frame.args[1])
     return out
     return out
end
end


return p
return p

Версия от 03:54, 22 октября 2023

Для документации этого модуля может быть создана страница Модуль:Meals Lookup/doc

local prototypes = mw.loadData("Module:Meals Lookup/data")
local e = require("Module:Entity_Lookup")

local p = {}
p.meals = prototypes.meals


function p.getrecipesfromtype(frame, type) -- {{#invoke:Meals Lookup|getrecipesfromtype|ProtoID}}
    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)
        out[ingredient] = amount
    end
    return out
end

function p.getmicrowaverecipereagents(frame, recipe)
    local out = {}
    for ingredient, amount in pairs(recipe["reagents"]) do
        -- table.insert(out, ingredient, amount)
        out[ingredient] = amount
    end
    return out
end

function p.buildsolids(frame, array)
    local out = ""
    for item, amount in pairs(array) do
        out = out .. frame:expandTemplate{ title = "Recipe Component", item = e.getname(frame, item), amount = amount}
    end
    return out
end

function p.buildreagents(frame, array)
    local out = ""
    for item, amount in pairs(array) do
        out = out .. frame:expandTemplate{ title = "Chem Recipe Component", reagent = item, amount = amount}
    end
    return out
end

function p.buildmicrowaverecipebox(frame, recipeId)
    local out = "hehe"
    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 = p.buildsolids(frame, p.getmicrowaverecipesolids(frame, recipe))
    local reagents = p.buildreagents(frame, p.getmicrowaverecipereagents(frame, recipe))
    out = frame:expandTemplate{ title = "Recipe Box", 
    name = e.getname(frame, recipe["result"]), 
    ["component-1"] = solids .. reagents, 
    transformer = frame:expandTemplate{title="Recipe Transformers", "microwaveRecipes", recipe["time"]}, 
    result = frame:expandTemplate{ title = "Recipe Component", item = e.getname(frame, recipe["result"])}}
    return out
end

-- returns all types for a recipe with given id, should not be used out of module
function p.getrecipetypes(frame, id)
    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

-- tests.
function p.tests(frame)
    local out = ""
    out = out .. p.buildsolids(frame, p.getrecipe(frame, frame.args[1], frame.args[2]))
    -- out = out .. p.buildmicrowaverecipebox(frame, frame.args[1])
    return out
end

return p