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

Материал из Space Station 14 Вики
Нет описания правки
Нет описания правки
Строка 6: Строка 6:




function p.getrecipesfromtype(frame, type) -- {{#invoke:Meals Lookup|getrecipesfromtype|ProtoID}}
function getrecipesfromtype(frame, type) -- {{#invoke:Meals Lookup|getrecipesfromtype|ProtoID}}
     return p.meals[type]
     return p.meals[type]
end
end


function p.getrecipe(frame, type, id)
function getrecipe(frame, type, id) -- should not be invoked
     return p.getrecipesfromtype(frame, type)[id:gsub(' ', '')]
     return getrecipesfromtype(frame, type)[id:gsub(' ', '')]
end
end


function p.getmicrowaverecipesolids(frame, recipe)
function getmicrowaverecipesolids(frame, recipe) -- should not be invoked
     local out = {}
     local out = {}
     for ingredient, amount in pairs(recipe["solids"]) do
     for ingredient, amount in pairs(recipe["solids"]) do
        -- table.insert(out, ingredient, amount)
         out[ingredient] = amount
         out[ingredient] = amount
     end
     end
Строка 23: Строка 22:
end
end


function p.getmicrowaverecipereagents(frame, recipe)
function getmicrowaverecipereagents(frame, recipe) -- should not be invoked
     local out = {}
     local out = {}
     for ingredient, amount in pairs(recipe["reagents"]) do
     for ingredient, amount in pairs(recipe["reagents"]) do
        -- table.insert(out, ingredient, amount)
         out[ingredient] = amount
         out[ingredient] = amount
     end
     end
Строка 32: Строка 30:
end
end


function p.buildsolids(frame, array)
function buildsolids(frame, array) -- should not be invoked
     local out = ""
     local out = ""
     for solid, amount in pairs(array) do
     for solid, amount in pairs(array) do
Строка 52: Строка 50:
     local out = "hehe"
     local out = "hehe"
     local id = frame.args[1]:gsub(' ', '')
     local id = frame.args[1]:gsub(' ', '')
     local recipe = p.getrecipe(frame, "microwaveRecipes", id)
     local recipe = getrecipe(frame, "microwaveRecipes", id)
     local solids = p.buildsolids(frame, p.getmicrowaverecipesolids(frame, recipe))
     local solids = buildsolids(frame, getmicrowaverecipesolids(frame, recipe))
     local reagents = p.buildreagents(frame, p.getmicrowaverecipereagents(frame, recipe))
     local reagents = p.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: Строка 59:
     "|result=".. frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}|image=Файл:Mousegif.gif}}" ) ..
     "|result=".. frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}|image=Файл:Mousegif.gif}}" ) ..
     "}}")
     "}}")
    -- 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
     return out
end
end
Строка 86: Строка 79:
function p.tests(frame)
function p.tests(frame)
     local out = ""
     local out = ""
     out = out .. p.buildsolids(frame, p.getmicrowaverecipesolids(frame, p.getrecipe(frame, frame.args[2], frame.args[1])))
     out = out .. buildsolids(frame, getmicrowaverecipesolids(frame, getrecipe(frame, frame.args[2], frame.args[1])))
     out = out .. "\n" .. p.buildreagents(frame, p.getmicrowaverecipereagents(frame, p.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 .. p.buildmicrowaverecipebox(frame, frame.args[1])
     -- out = out .. p.buildmicrowaverecipebox(frame, frame.args[1])

Версия от 06:05, 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 getrecipesfromtype(frame, type) -- {{#invoke:Meals Lookup|getrecipesfromtype|ProtoID}}
    return p.meals[type]
end

function getrecipe(frame, type, id) -- should not be invoked
    return getrecipesfromtype(frame, type)[id:gsub(' ', '')]
end

function getmicrowaverecipesolids(frame, recipe) -- should not be invoked
    local out = {}
    for ingredient, amount in pairs(recipe["solids"]) do
        out[ingredient] = amount
    end
    return out
end

function getmicrowaverecipereagents(frame, recipe) -- should not be invoked
    local out = {}
    for ingredient, amount in pairs(recipe["reagents"]) do
        out[ingredient] = amount
    end
    return out
end

function buildsolids(frame, array) -- should not be invoked
    local out = ""
    for solid, amount in pairs(array) do
        out = out .. frame:preprocess( "{{Recipe Component|item={{#invoke:Entity Lookup|getname|".. solid .."}}|image=Файл:Mousegif.gif|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}
        out = out .. frame:preprocess( "{{Chem Recipe Component|reagent=".. item .."|amount={{{"..amount.."|1}}}}}" )
    end
    return out
end

function p.buildmicrowaverecipebox(frame)
    local out = "hehe"
    local id = frame.args[1]:gsub(' ', '')
    local recipe = getrecipe(frame, "microwaveRecipes", id)
    local solids = buildsolids(frame, getmicrowaverecipesolids(frame, recipe))
    local reagents = p.buildreagents(frame, getmicrowaverecipereagents(frame, recipe))
    out = frame:preprocess("{{Recipe Box"..
    "|name={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}"..
    "|component-1="..solids .. "\n" .. reagents..
    "|transformer={{Recipe Transformers|microwaveRecipes|"..recipe["time"].."}}"..
    "|result=".. frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}|image=Файл:Mousegif.gif}}" ) ..
    "}}")
    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 .. 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 .. p.buildmicrowaverecipebox(frame, frame.args[1])
    return out
end

return p