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

Материал из Space Station 14 Вики
Нет описания правки
Нет описания правки
 
(не показано 12 промежуточных версий 2 участников)
Строка 1: Строка 1:
local prototypes = mw.loadData("Module:Entity Lookup/data")
local prototypes = mw.loadData("Module:Meals Lookup/data")
local chem = mw.loadData("Module:Chemistry Lookup/data")


local p = {}
local p = {}
p.entities = prototypes.entities
p.meals = prototypes.meals
p.chemicals = chem.react


--#region universal


function p.xd(frame)
function table.containsv(table, value) -- FUCKING LUA
     -- body
    -- containsv = contains value
     local out = frame:expandTemplate{ title = "Temperature", args = { min = 322, max = "Infinity" }}
    for _, v in pairs(table) do
        if v == value then
            return true
        end
    end
    return false
end
 
function table.containsk(table, key) -- FUCKING LUA
    -- containsk = contains key
    for k, _ in pairs(table) do
        if k == key then
            return true
        end
    end
    return false
end
 
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
     return out
end
end


function getimage(frame, fileid) -- should not be invoked
    local out = ""
    --[[
        WARNING!! THE NEXT THING IS "EXPENSIVE" AND DOES NOT WORKS AFTER 30 OR SMTHNG RUNS
        read https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Expensive_properties for more info
        local gifFileTitle = mw.title.new(fileid .. ".gif", "File")
        local pngFileTitle = mw.title.new(fileid .. ".png", "File")
        if gifFileTitle.file.exists then
            out = "File:" .. fileid .. ".gif"
        elseif pngFileTitle.file.exists then
            out = "File:" .. fileid .. ".png"
        else
            out = ""
        end
    --]]


function p.mhamstersandbox(frame)
     -- less expensive variant, but returns only png (AND BIG RED TEXT IF PNG DOES NOT EXISTS)
     -- body
     out = "File:" .. fileid .. ".png"
     local out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { frame.args[1], "Нижний правый текст", "FreedomImplant", "Файл:Honks.gif" }}
     return out
     return out
end
end


function p.createtexttooltip(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|img=картиночка}}
function buildsolids(frame, array) -- should not be invoked
     local out = " "
     local out = ""
     local entity = p.entities[frame.args[2]]
     for solid, amount in pairs(array) do
    -- local pic = frame.args[3]
        out = out ..
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
            frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|" ..
    if entity ~= nil then do
                solid .. "}}|image=" .. getimage(frame, solid) .. "|amount=" .. amount .. "}}")
    if frame.args["img"] ~= nil then do
    -- pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
    out =  frame:expandTemplate{ title = "Tooltip", args = { frame.args[1], entity.name, entity.desc, stats, img=frame.args["img"] }}
    end else
    out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  entity.name, entity.desc, stats }}
    end
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
    end else
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "Не найден", "Предмет не найден", img=frame.args[3]}}
     end
     end
     return out
     return out
end
end


function p.createtexttooltippartii(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function buildreagents(frame, array) -- should not be invoked
     local out = " "
     local out = ""
     local entity = p.entities[frame.args[2]]
     for item, amount in pairs(array) do
    local pic = frame.args[3]
        out = out .. frame:preprocess("{{Chem Recipe Component|reagent=" .. item .. "|amount=" .. amount .. "}}")
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
    if entity ~= nil then do
    if frame.args[3] ~= nil then do
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
    out =  frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args[1], entity.name, entity.desc, frame.args[3] }}
    end else
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args[1],  entity.name, entity.desc}}
    end
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
    end else
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
     end
     end
     return out
     return out
end
end


function p.createtexttooltippartiii(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function getrecipesbyname(frame, str) -- should not be inviked
     local out = " "
     local out = {}
     local entity = p.entities[frame.args[2]]
     for type, recipes in pairs(p.meals) do
    local pic = frame.args[3]
        out[type]= {}
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
        for recipeId, recipe in pairs(recipes) do
    if entity ~= nil then do
            if string.match(recipeId, str) then
    if frame.args[3] ~= nil then do
                table.insert(out[type], recipe)
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
            end
    out =  frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xdi", frame.args[1], entity.name, entity.desc, pic=frame.args[3]}}
        end
    end else
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args[1], entity.name, entity.desc}}
    end
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
    end else
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
     end
     end
     return out
     return out
end
end


function p.createtexttooltippartiv(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function getotherrecipes(frame, tabl, str)
     local out = " "
     local out = {}
     local entity = p.entities[frame.args[2]]
     for type, recipes in pairs(tabl) do
    local pic = frame.args[3]
        if not table.containsk(out, type) then
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
            out[type]= {}
    if entity ~= nil then do
        end
    if frame.args[3] ~= nil then do
        for recipeId, recipe in pairs(recipes) do
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
            if not string.match(recipeId, str) then
    out =  frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xdii", frame.args[1], entity.name, frame.args[3], desc=entity.desc}}
                if not table.containsv(out[type], recipe) then
    end else
                    table.insert(out[type], recipe)
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args[1],  entity.name, entity.desc}}
                end
    end
            end
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
        end
    end else
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
     end
     end
     return out
     return out
end
end


function p.createtexttooltippartv(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
 
     local out = " "
function p.imageslist(frame)
     local entity = p.entities[frame.args[2]]
     local out = "'''REQUIRED IMAGES:'''<br>"
    local pic = frame.args[3]
     for cat, recipes in pairs(p.meals) do
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
        for id, recipe in pairs(recipes) do
    if entity ~= nil then do
            if cat == "microwaveRecipes" then
    if frame.args[3] ~= nil then do
                do
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
                    out = out .. recipe["result"] .. ": [[:File:" .. recipe["result"] .. ".png]]<br>"
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args[1], entity.name, entity.desc, frame.args["Pic"] }}
                    if #recipe["solids"] > 0 then
    end else
                        do
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args[1],  entity.name, entity.desc}}
                            for solid in pairs(getmicrowaverecipesolids(recipe)) do
    end
                                out = out .. solid .. ": [[:File:" .. solid .. ".png]]<br>"
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
                            end
    end else
                        end
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1]"[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
                    end
                end
            end
            if cat == "sliceableRecipes" or cat == "heatableRecipes" or cat == "toolmadeRecipes" then
                do
                    out = out .. recipe["result"] .. ": [[:File:" .. recipe["result"] .. ".png]]<br>"
                    out = out .. recipe["input"] .. ": [[:File:" .. recipe["input"] .. ".png]]<br>"
                end
            end
            if cat == "grindableRecipes" then
                do
                    out = out .. recipe["input"] .. ": [[:File:" .. recipe["input"] .. ".png]]<br>"
                end
            end
        end
     end
     end
    out = out .. "<br><hr>"
    return out
end
function p.buildeverything(frame)
    local out = ""
    out = out .. p.buildmicrowaverecipes(frame)
    out = out .. p.buildslicerecipes(frame)
    out = out .. p.buildgrindrecipes(frame)
    out = out .. p.buildheatrecipes(frame)
    out = out .. p.buildtoolmaderecipes(frame)
    out = out .. p.buildixablerecipes(frame)
     return out
     return out
end
end


function p.createtexttooltippartvi(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
--#endregion
    local out = " "
 
    local entity = p.entities[frame.args[1]]
--#region microwaveRecipes
    local pic = frame.args[2]
 
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
function getmicrowaverecipesolids(frame, recipe) -- should not be invoked
     if entity ~= nil then do
     local out = {}
    if frame.args[3] ~= nil then do
    for ingredient, amount in pairs(recipe["solids"]) do
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
        out[ingredient] = amount
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args["Текст"], entity.name, entity.desc, frame.args[3] }}
    end else
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args["Текст"],  entity.name, entity.desc}}
    end
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
    end else
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
     end
     end
     return out
     return out
end
end


function p.createtexttooltippartvii(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function getmicrowaverecipereagents(frame, recipe) -- should not be invoked
     local out = " "
     local out = {}
    local entity = p.entities[frame.args[1]]
     for ingredient, amount in pairs(recipe["reagents"]) do
    local pic = frame.args[2]
        out[ingredient] = amount
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
     if entity ~= nil then do
    if frame.args[3] ~= nil then do
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
    out =  frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args["Text"], entity.name, entity.desc, frame.args[3] }}
    end else
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args["Text"],  entity.name, entity.desc}}
    end
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
    end else
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
     end
     end
     return out
     return out
end
end


function p.createtexttooltippartviii(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function p.buildmicrowaverecipebox(frame) -- {{#invoke:Meals Lookup|buildmicrowaverecipebox|MicrowaveRecipeID}}
     local out = " "
     local out = ""
     local entity = p.entities[frame.args[2]]
     local id = frame.args[1]:gsub(' ', '')
     local pic = frame.args[3]
    local recipe = getrecipe(frame, "microwaveRecipes", id)
     local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
     local solids = buildsolids(frame, getmicrowaverecipesolids(frame, recipe))
    if entity ~= nil then do
     local reagents = buildreagents(frame, getmicrowaverecipereagents(frame, recipe))
    if frame.args[3] ~= nil then do
    out = frame:preprocess("{{Recipe Box" ..
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
        "|name={{#invoke:Entity Lookup|getname|" .. recipe["result"] .. "}}" ..
    out =  frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", frame.args[1], entity.name, entity.desc, frame.args[3] }}
        "|component-1=" .. solids .. "\n" .. reagents ..
    end else
        "|transformer={{Recipe Transformers|microwaveRecipes|" .. recipe["time"] .. "}}" ..
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", frame.args[1],  entity.name, entity.desc}}
        "|result=" ..
    end
        frame:preprocess("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
            recipe["result"] .. "}}|image=" .. getimage(frame, recipe["result"]) .. "}}") ..
     end else
        "}}")
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
     return out
end
 
function p.buildmicrowaverecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "microwaveRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildmicrowaverecipebox|" .. id .. "}}") .. "\n"
     end
     end
     return out
     return out
end
end


function p.createtexttooltippartix(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
--#endregion microwaveRecipes
     local out = " "
 
     local entity = p.entities[frame.args[2]]
--#region sliceableRecipes
     local pic = frame.args[3]
 
     local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
function p.buildslicerecipebox(frame) -- {{#invoke:Meals Lookup|buildslicerecipebox|SliceableRecipeID}}
    if entity ~= nil then do
     local out = ""
    if frame.args[3] ~= nil then do
     local id = frame.args[1]:gsub(' ', '')
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
     local recipe = getrecipe(frame, "sliceableRecipes", id)
    out =  frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lolone", entity.name, entity.desc, frame.args[3], Text=frame.args[1] }}
     out = frame:preprocess("{{Recipe Box" ..
    end else
        "|name={{#invoke:Entity Lookup|getname|" .. recipe["result"] .. "}}" ..
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", frame.args[1],  entity.name, entity.desc}}
        "|component-1=" ..
    end
        frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|" ..
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
            recipe["input"] .. "}}|image=" .. getimage(frame, recipe["input"]) .. "}}") ..
     end else
        "|transformer={{Recipe Transformers|sliceableRecipes}}" ..
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
        "|result=" ..
        frame:preprocess("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
            recipe["result"] .. "}}|image=" .. getimage(frame, recipe["result"]) .. "|amount=" .. recipe["count"] .. "}}") ..
        "}}")
     return out
end
 
function p.buildslicerecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "sliceableRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildslicerecipebox|" .. id .. "}}") .. "\n"
     end
     end
     return out
     return out
end
end


function p.createtexttooltippartx(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
--#endregion sliceableRecipes
     local out = " "
 
     local entity = p.entities[frame.args[2]]
--#region grindableRecipes
     local pic = frame.args[3]
 
     local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
function p.buildgrindrecipebox(frame) -- {{#invoke:Meals Lookup|buildgrindrecipebox|GrindableRecipeID}}
     if entity ~= nil then do
     local out = ""
    if frame.args[3] ~= nil then do
     local id = frame.args[1]:gsub(' ', '')
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
     local recipe = getrecipe(frame, "grindableRecipes", id)
    out =  frame:expandTemplate{ title = "Mhamster/sandbox", args = { "loltwo", frame.args[1], entity.name, entity.desc, pic=frame.args[3] }}
     local reagents = buildreagents(frame, recipe["result"])
    end else
     out = frame:preprocess("{{Recipe Box" ..
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", frame.args[1],  entity.name, entity.desc}}
        "|name={{#invoke:Entity Lookup|getname|" .. recipe["id"] .. "}}" ..
    end
        "|component-1=" ..
     -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
        frame:preprocess("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
     end else
            recipe["input"] .. "}}|image=" .. getimage(frame, recipe["input"]) .. "}}") ..
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
        "|transformer={{Recipe Transformers|grindableRecipes}}" ..
        "|result=" .. reagents ..
        "}}")
    return out
end
 
function p.buildgrindrecipes(frame)
     local out = ""
     for id in pairs(getrecipesfromtype(frame, "grindableRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildgrindrecipebox|" .. id .. "}}") .. "\n"
     end
     end
     return out
     return out
end
end


function p.createtexttooltippartxi(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
--#endregion grindableRecipes
     local out = " "
 
     local entity = p.entities[frame.args[1]]
--#region heatableRecipes
     local pic = frame.args[2]
 
     local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
function p.buildheatrecipebox(frame) -- {{#invoke:Meals Lookup|buildheatrecipebox|HeatableRecipeID}}
    if entity ~= nil then do
     local out = ""
    if frame.args[3] ~= nil then do
     local id = frame.args[1]:gsub(' ', '')
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
     local recipe = getrecipe(frame, "heatableRecipes", id)
    out =  frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", frame.args["Text"], entity.name, entity.desc, frame.args[2] }}
     out = frame:preprocess("{{Recipe Box" ..
    end else
        "|name={{#invoke:Entity Lookup|getname|" .. recipe["result"] .. "}}" ..
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args[1], entity.name, entity.desc}}
        "|component-1=" ..
    end
        frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|" ..
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
            recipe["input"] .. "}}|image=" .. getimage(frame, recipe["input"]) .. "}}") ..
     end else
        "|transformer={{Recipe Transformers|heatableRecipes|" .. recipe["minTemp"] .. "}}" ..
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
        "|result=" ..
        frame:preprocess("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
            recipe["result"] .. "}}|image=" .. getimage(frame, recipe["result"]) .. "}}") ..
        "}}")
    return out
end
 
function p.buildheatrecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "heatableRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildheatrecipebox|" .. id .. "}}") .. "\n"
    end
    return out
end
 
--#endregion heatableRecipes
 
--#region toolmadeRecipes
 
function p.buildtoolmaderecipebox(frame) -- {{#invoke:Meals Lookup|buildtoolmaderecipebox|ToolmadeRecipeID}}
    local out = ""
    local id = frame.args[1]:gsub(' ', '')
    local recipe = getrecipe(frame, "toolmadeRecipes", id)
    local transformer = "toolmadeRecipes" .. recipe["tool"]
    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=" .. getimage(frame, recipe["input"]) .. "}}") ..
        "|transformer={{Recipe Transformers|" .. transformer .. "}}" ..
        "|result=" ..
        frame:preprocess("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
            recipe["result"] .. "}}|image=" .. getimage(frame, recipe["result"]) .. "}}") ..
        "}}")
     return out
end
 
function p.buildtoolmaderecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "toolmadeRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildtoolmaderecipebox|" .. id .. "}}") .. "\n"
     end
     end
     return out
     return out
end
end


function p.createtexttooltippartxii(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
--#endregion toolmadeRecipes
     local out = " "
 
     local entity = p.entities[frame.args[2]]
--#region mixableRecipes
     local pic = frame.args[3]
 
     local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
function getchemicalreagents(recipe) -- should not be invoked
     if entity ~= nil then do
    local out = {}
     if frame.args[3] ~= nil then do
    for ingredient, data in pairs(recipe["reactants"]) do
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
        out[ingredient] = data["amount"]
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", frame.args[1], entity.name, entity.desc, frame.args["pic"] }}
    end
    end else
    return out
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args[1],  entity.name, entity.desc}}
end
    end
 
     -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
function p.buildmixablerecipebox(frame) -- {{#invoke:Meals Lookup|buildmixablerecipebox|MixableRecipeID}}
     end else
     local out = ""
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
     local id = frame.args[1]:gsub(' ', '')
     local recipe = p.chemicals[id]
     local input = buildreagents(frame, getchemicalreagents(recipe))
   
    local results = {}
     for _, v in pairs(recipe["effects"]) do
     table.insert(results, v.description)
    end
   
    local result = table.concat(results, "\n")
   
    out = frame:preprocess("{{Recipe Box" ..
        "|component-1=" .. input ..
        "|name= " ..
        "|transformer={{Recipe Transformers|mixableRecipes}}" ..
        "|result=" .. result .. "}}")
    return out
end
 
function p.buildixablerecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "mixableRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Sandbox|buildmixablerecipebox|" .. id .. "}}") .. "\n"
    end
     return out
end
 
--#endregion mixableRecipes
 
--#region dishes
function p.soups(frame)
    local out = ""
     return out
end
--#endregion
 
 
-- tests.
function p.tests(frame)
    local out = ""
    local tablo = p.meals
    for _, patt in pairs(frame.args) do
        for type, recipes in pairs(getotherrecipes(frame, tablo, patt)) do
            out = out .. type .. "("
            for k, r in pairs(recipes) do
                out = out .. " " .. k .. ":" .. r["id"]
            end
            out = out .. ")"
        end
     end
     end
     return out
     return out
end
end
-- function p.tests(frame)
--    local out = ""
--    for type, recipes in pairs(getrecipesbyname(frame, "[Dd]ough")) do
--        out = out .. type .. "("
--        for k, r in pairs(recipes) do
--            out = out .. " " .. k .. ":" .. r["id"]
--        end
--        out = out .. ")"
--    end
--    return out
-- end


return p
return p

Текущая версия от 14:00, 4 мая 2024

Это модуль для тестирования механик модулей без создания отдельного модуля для тестирования каждого модуля. Просто дописывайте свою функцию к классу p и используйте на странице, as shrimple as that (должно быть)


local prototypes = mw.loadData("Module:Meals Lookup/data")
local chem = mw.loadData("Module:Chemistry Lookup/data")

local p = {}
p.meals = prototypes.meals
p.chemicals = chem.react

--#region universal

function table.containsv(table, value) -- FUCKING LUA
    -- containsv = contains value
    for _, v in pairs(table) do
        if v == value then
            return true
        end
    end
    return false
end

function table.containsk(table, key) -- FUCKING LUA
    -- containsk = contains key
    for k, _ in pairs(table) do
        if k == key then
            return true
        end
    end
    return false
end

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 getimage(frame, fileid) -- should not be invoked
    local out = ""
    --[[
        WARNING!! THE NEXT THING IS "EXPENSIVE" AND DOES NOT WORKS AFTER 30 OR SMTHNG RUNS
        read https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Expensive_properties for more info
        local gifFileTitle = mw.title.new(fileid .. ".gif", "File")
        local pngFileTitle = mw.title.new(fileid .. ".png", "File")
        if gifFileTitle.file.exists then
            out = "File:" .. fileid .. ".gif"
        elseif pngFileTitle.file.exists then
            out = "File:" .. fileid .. ".png"
        else
            out = ""
        end
    --]]

    -- less expensive variant, but returns only png (AND BIG RED TEXT IF PNG DOES NOT EXISTS)
    out = "File:" .. fileid .. ".png"
    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=" .. getimage(frame, solid) .. "|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:preprocess("{{Chem Recipe Component|reagent=" .. item .. "|amount=" .. amount .. "}}")
    end
    return out
end

function getrecipesbyname(frame, str) -- should not be inviked
    local out = {}
    for type, recipes in pairs(p.meals) do
        out[type]= {}
        for recipeId, recipe in pairs(recipes) do
            if string.match(recipeId, str) then
                table.insert(out[type], recipe)
            end
        end
    end
    return out
end

function getotherrecipes(frame, tabl, str)
    local out = {}
    for type, recipes in pairs(tabl) do
        if not table.containsk(out, type) then
            out[type]= {}
        end
        for recipeId, recipe in pairs(recipes) do
            if not string.match(recipeId, str) then
                if not table.containsv(out[type], recipe) then
                    table.insert(out[type], recipe)
                end
            end
        end
    end
    return out
end


function p.imageslist(frame)
    local out = "'''REQUIRED IMAGES:'''<br>"
    for cat, recipes in pairs(p.meals) do
        for id, recipe in pairs(recipes) do
            if cat == "microwaveRecipes" then
                do
                    out = out .. recipe["result"] .. ": [[:File:" .. recipe["result"] .. ".png]]<br>"
                    if #recipe["solids"] > 0 then
                        do
                            for solid in pairs(getmicrowaverecipesolids(recipe)) do
                                out = out .. solid .. ": [[:File:" .. solid .. ".png]]<br>"
                            end
                        end
                    end
                end
            end
            if cat == "sliceableRecipes" or cat == "heatableRecipes" or cat == "toolmadeRecipes" then
                do
                    out = out .. recipe["result"] .. ": [[:File:" .. recipe["result"] .. ".png]]<br>"
                    out = out .. recipe["input"] .. ": [[:File:" .. recipe["input"] .. ".png]]<br>"
                end
            end
            if cat == "grindableRecipes" then
                do
                    out = out .. recipe["input"] .. ": [[:File:" .. recipe["input"] .. ".png]]<br>"
                end
            end
        end
    end
    out = out .. "<br><hr>"
    return out
end

function p.buildeverything(frame)
    local out = ""
    out = out .. p.buildmicrowaverecipes(frame)
    out = out .. p.buildslicerecipes(frame)
    out = out .. p.buildgrindrecipes(frame)
    out = out .. p.buildheatrecipes(frame)
    out = out .. p.buildtoolmaderecipes(frame)
    out = out .. p.buildixablerecipes(frame)
    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("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
            recipe["result"] .. "}}|image=" .. getimage(frame, recipe["result"]) .. "}}") ..
        "}}")
    return out
end

function p.buildmicrowaverecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "microwaveRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildmicrowaverecipebox|" .. id .. "}}") .. "\n"
    end
    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=" .. getimage(frame, recipe["input"]) .. "}}") ..
        "|transformer={{Recipe Transformers|sliceableRecipes}}" ..
        "|result=" ..
        frame:preprocess("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
            recipe["result"] .. "}}|image=" .. getimage(frame, recipe["result"]) .. "|amount=" .. recipe["count"] .. "}}") ..
        "}}")
    return out
end

function p.buildslicerecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "sliceableRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildslicerecipebox|" .. id .. "}}") .. "\n"
    end
    return out
end

--#endregion sliceableRecipes

--#region grindableRecipes

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

function p.buildgrindrecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "grindableRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildgrindrecipebox|" .. id .. "}}") .. "\n"
    end
    return out
end

--#endregion grindableRecipes

--#region heatableRecipes

function p.buildheatrecipebox(frame) -- {{#invoke:Meals Lookup|buildheatrecipebox|HeatableRecipeID}}
    local out = ""
    local id = frame.args[1]:gsub(' ', '')
    local recipe = getrecipe(frame, "heatableRecipes", 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=" .. getimage(frame, recipe["input"]) .. "}}") ..
        "|transformer={{Recipe Transformers|heatableRecipes|" .. recipe["minTemp"] .. "}}" ..
        "|result=" ..
        frame:preprocess("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
            recipe["result"] .. "}}|image=" .. getimage(frame, recipe["result"]) .. "}}") ..
        "}}")
    return out
end

function p.buildheatrecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "heatableRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildheatrecipebox|" .. id .. "}}") .. "\n"
    end
    return out
end

--#endregion heatableRecipes

--#region toolmadeRecipes

function p.buildtoolmaderecipebox(frame) -- {{#invoke:Meals Lookup|buildtoolmaderecipebox|ToolmadeRecipeID}}
    local out = ""
    local id = frame.args[1]:gsub(' ', '')
    local recipe = getrecipe(frame, "toolmadeRecipes", id)
    local transformer = "toolmadeRecipes" .. recipe["tool"]
    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=" .. getimage(frame, recipe["input"]) .. "}}") ..
        "|transformer={{Recipe Transformers|" .. transformer .. "}}" ..
        "|result=" ..
        frame:preprocess("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
            recipe["result"] .. "}}|image=" .. getimage(frame, recipe["result"]) .. "}}") ..
        "}}")
    return out
end

function p.buildtoolmaderecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "toolmadeRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildtoolmaderecipebox|" .. id .. "}}") .. "\n"
    end
    return out
end

--#endregion toolmadeRecipes

--#region mixableRecipes

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

function p.buildmixablerecipebox(frame) -- {{#invoke:Meals Lookup|buildmixablerecipebox|MixableRecipeID}}
    local out = ""
    local id = frame.args[1]:gsub(' ', '')
    local recipe = p.chemicals[id]
    local input = buildreagents(frame, getchemicalreagents(recipe))
    
    local results = {}
    for _, v in pairs(recipe["effects"]) do
    	table.insert(results, v.description)
    end
    
    local result = table.concat(results, "\n")
    
    out = frame:preprocess("{{Recipe Box" ..
        "|component-1=" .. input ..
        "|name= " ..
        "|transformer={{Recipe Transformers|mixableRecipes}}" ..
        "|result=" .. result .. "}}")
    return out
end

function p.buildixablerecipes(frame)
    local out = ""
    for id in pairs(getrecipesfromtype(frame, "mixableRecipes")) do
        out = out .. frame:preprocess("{{#invoke:Sandbox|buildmixablerecipebox|" .. id .. "}}") .. "\n"
    end
    return out
end

--#endregion mixableRecipes

--#region dishes
function p.soups(frame)
    local out = ""
    return out
end
--#endregion


-- tests.
function p.tests(frame)
    local out = ""
    local tablo = p.meals
    for _, patt in pairs(frame.args) do
        for type, recipes in pairs(getotherrecipes(frame, tablo, patt)) do
            out = out .. type .. "("
            for k, r in pairs(recipes) do
                out = out .. " " .. k .. ":" .. r["id"]
            end
            out = out .. ")"
        end
    end
    return out
end
-- function p.tests(frame)
--     local out = ""
--     for type, recipes in pairs(getrecipesbyname(frame, "[Dd]ough")) do
--         out = out .. type .. "("
--         for k, r in pairs(recipes) do
--             out = out .. " " .. k .. ":" .. r["id"]
--         end
--         out = out .. ")"
--     end
--     return out
-- end

return p