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

Материал из Space Station 14 Вики
Нет описания правки
Нет описания правки
Строка 82: Строка 82:
--#region sliceableRecipes
--#region sliceableRecipes


function p.buildmslicerecipebox(frame) -- {{#invoke:Meals Lookup|buildmslicerecipebox|SliceableRecipeID}}
function p.buildslicerecipebox(frame) -- {{#invoke:Meals Lookup|buildslicerecipebox|SliceableRecipeID}}
     local out = ""
     local out = ""
     local id = frame.args[1]:gsub(' ', '')
     local id = frame.args[1]:gsub(' ', '')
Строка 99: Строка 99:
--#region grindableRecipes
--#region grindableRecipes


function p.buildmgrindrecipebox(frame) -- {{#invoke:Meals Lookup|buildmslicerecipebox|SliceableRecipeID}}
function p.buildgrindrecipebox(frame) -- {{#invoke:Meals Lookup|buildslicerecipebox|SliceableRecipeID}}
     local out = ""
     local out = ""
     local id = frame.args[1]:gsub(' ', '')
     local id = frame.args[1]:gsub(' ', '')
     local recipe = getrecipe("sliceableRecipes", id)
     local recipe = getrecipe("grindableRecipes", id)
     local result = buildreagents(frame, recipe["result"])
     local result = buildreagents(frame, recipe["result"])
     out = frame:preprocess("{{Recipe Box"..
     out = frame:preprocess("{{Recipe Box"..
Строка 119: Строка 119:
     local out = ""
     local out = ""
     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 .. "\n" .. frame:preprocess("{{#invoke:Meals Lookup|buildslicerecipebox|".. frame.args[2] .. "}}")
     -- out = out .. p.buildmicrowaverecipebox(frame, frame.args[1])
     out = out .. "\n" .. frame:preprocess("{{#invoke:Meals Lookup|buildgrindrecipebox|".. frame.args[3] .. "}}")
     return out
     return out
end
end


return p
return p

Версия от 06:56, 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

--#region universal
function getrecipesfromtype(frame, type) -- should not be invoked
    return p.meals[type]
end

function getrecipe(frame, type, id) -- should not be invoked
    return getrecipesfromtype(frame, type)[id:gsub(' ', '')]
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


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 buildreagents(frame, array) -- should not be invoked
    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
--#endregion

--#region microwaveRecipes
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 p.buildmicrowaverecipebox(frame) -- {{#invoke:Meals Lookup|buildmicrowaverecipebox|MicrowaveRecipeID}}
    local out = ""
    local id = frame.args[1]:gsub(' ', '')
    local recipe = getrecipe(frame, "microwaveRecipes", id)
    local solids = buildsolids(frame, getmicrowaverecipesolids(frame, recipe))
    local reagents = 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
--#endregion microwaveRecipes

--#region sliceableRecipes

function p.buildslicerecipebox(frame) -- {{#invoke:Meals Lookup|buildslicerecipebox|SliceableRecipeID}}
    local out = ""
    local id = frame.args[1]:gsub(' ', '')
    local recipe = getrecipe(frame, "sliceableRecipes", id)
    out = frame:preprocess("{{Recipe Box"..
    "|name={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}"..
    "|component-1="..frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|".. recipe["input"] .."}}|image=Файл:Mousegif.gif}}" ) ..
    "|transformer={{Recipe Transformers|sliceableRecipes}}"..
    "|result=".. frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}|image=Файл:Mousegif.gif|amount="..recipe["count"].."}}" ) ..
    "}}")
    return out
end

--#endregion sliceableRecipes

--#region grindableRecipes

function p.buildgrindrecipebox(frame) -- {{#invoke:Meals Lookup|buildslicerecipebox|SliceableRecipeID}}
    local out = ""
    local id = frame.args[1]:gsub(' ', '')
    local recipe = getrecipe("grindableRecipes", id)
    local result = buildreagents(frame, recipe["result"])
    out = frame:preprocess("{{Recipe Box"..
    "|name={{#invoke:Entity Lookup|getname|".. recipe["result"] .."}}"..
    "|component-1="..frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|".. recipe["input"] .."}}|image=Файл:Mousegif.gif}}" ) ..
    "|transformer={{Recipe Transformers|grindableRecipes}}"..
    "|result=".. result ..
    "}}")
    return out
end

--#endregion grindableRecipes

-- tests.
function p.tests(frame)
    local out = ""
    out = out .. "\n" .. frame:preprocess("{{#invoke:Meals Lookup|buildmicrowaverecipebox|".. frame.args[1] .. "}}")
    out = out .. "\n" .. frame:preprocess("{{#invoke:Meals Lookup|buildslicerecipebox|".. frame.args[2] .. "}}")
    out = out .. "\n" .. frame:preprocess("{{#invoke:Meals Lookup|buildgrindrecipebox|".. frame.args[3] .. "}}")
    return out
end

return p