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

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


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


function p.readscalar(frame)
--#region universal
return mw.text.nowiki(p.chem[frame.args[1]][frame.args[2]])
 
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
end


function p.readscalarreact(frame)
function table.containsk(table, key) -- FUCKING LUA
if p.react[frame.args[1]][frame.args[2]] ~= nil then
    -- containsk = contains key
return mw.text.nowiki(p.react[frame.args[1]][frame.args[2]])
    for k, _ in pairs(table) do
else
        if k == key then
return ""
            return true
end
        end
    end
    return false
end
end


function p.getcolor(frame)
function getrecipesfromtype(frame, type) -- should not be invoked
return mw.text.nowiki(p.chem[frame.args[1]].color:sub(1, 7))
    return p.meals[type]
end
end


function p.gettextcolor(frame)
function getrecipe(frame, type, id) -- should not be invoked
local basecol = p.chem[frame.args[1]].color
    return getrecipesfromtype(frame, type)[id:gsub(' ', '')]
local red = tonumber(basecol:sub(2, 3), 16)
local grn = tonumber(basecol:sub(4, 5), 16)
local blu = tonumber(basecol:sub(6, 7), 16)
local luminance = math.sqrt(0.241*red*red + 0.691*grn*grn + 0.068*blu*blu)
if luminance > 100 then
return mw.text.nowiki("#000")
else
return mw.text.nowiki("#FFF")
end
end
end


function p.hasrecipe(frame)
function getrecipetypes(frame, id) -- should not be invoked
return p.chem[frame.args[1]]["recipes"][1] ~= nil
    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
end


function p.buildboxes(frame)
function buildsolids(frame, array) -- should not be invoked
local out = ""
    local out = ""
local group = frame.args[1]
    for solid, amount in pairs(array) do
for k in pairs(p.chem) do
        out = out ..
if p.chem[k].group == group then
            frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|" ..
out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
                solid .. "}}|image=" .. getimage(frame, solid) .. "|amount=" .. amount .. "}}")
elseif group == nil then
    end
out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
    return out
end
end
return out
end
end


function p.buildreactboxes(frame)
function buildreagents(frame, array) -- should not be invoked
local out = ""
    local out = ""
for k in pairs(p.react) do
    for item, amount in pairs(array) do
if tablelength(p.react[k].effects) ~= 0 then
        out = out .. frame:preprocess("{{Chem Recipe Component|reagent=" .. item .. "|amount=" .. amount .. "}}")
out = out .. frame:expandTemplate{ title = "Reactionbox", args = { reaction = k }}
    end
end
    return out
end
return out
end
end


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


function p.buildreactionext(frame)
function getotherrecipes(frame, tabl, str)
local react = frame.args[1]
    local out = {}
return p.buildreaction(frame, react)
    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
end


function p.buildreaction(frame, react)
local data = p.react[react]
local dest = "Chemistry"
local args = {}
local i = 0
for k,v in pairs(data.reactants) do
i = i + 1
local dest = "Chemistry"
if (p.groupDirection[p.chem[k].group] ~= nil) then
dest = p.groupDirection[p.chem[k].group]
end
args["component-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = k, amount = v.amount, dest = dest }}
end
i = 0
for k,v in pairs(data.products) do
i = i + 1
local dest = "Chemistry"
if (p.groupDirection[p.chem[k].group] ~= nil) then
dest = p.groupDirection[p.chem[k].group]
end
args["result-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = k, amount = v, dest = dest }}
end
if data.effects ~= nil then
args.effects = p.geneffectlist(data.effects, frame, 1)
end


return frame:expandTemplate{ title = "Chem Box Recipe", args = args }
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
end


function p.checksatiatesthirst(frame)
function p.buildeverything(frame)
local chem = frame.args[1]
    local out = ""
local met = p.chem[chem].metabolisms
    out = out .. p.buildmicrowaverecipes(frame)
if met == nil then
    out = out .. p.buildslicerecipes(frame)
return ""
    out = out .. p.buildgrindrecipes(frame)
end
    out = out .. p.buildheatrecipes(frame)
for k, v in pairs(met) do
    out = out .. p.buildtoolmaderecipes(frame)
for l, w in pairs(v.effects) do
    out = out .. p.buildixablerecipes(frame)
if w.id == "SatiateThirst" then
    return out
return "1"
end
end
end
return ""
end
end


function p.checksatiateshunger(frame)
function p.getPagesInCategory()
local chem = frame.args[1]
    local categoryName = "Викиделы"  -- Задайте название категории здесь
local met = p.chem[chem].metabolisms
    local categoryPages = {}
if met == nil then
   
return ""
    for page in mw.parse.categoryPages(categoryName) do
end
        table.insert(categoryPages, page.title)
for k, v in pairs(met) do
    end
for l, w in pairs(v.effects) do
 
if w.id == "SatiateHunger" then
    if #categoryPages == 0 then
return "1"
        return "Нет страниц в категории '" .. categoryName .. "'."
end
    end
end
 
end
    local result = "Страницы в категории '" .. categoryName .. "':\n"
return ""
    for _, title in ipairs(categoryPages) do
        result = result .. "* [[ " .. title .. " ]]\n"
    end
 
    return result
end
end


function p.haseffects(frame)
--#endregion
local chem = frame.args[1]
 
local met = p.chem[chem].metabolisms
--#region microwaveRecipes
if met == nil then
 
return ""
function getmicrowaverecipesolids(frame, recipe) -- should not be invoked
end
    local out = {}
for k, v in pairs(met) do
    for ingredient, amount in pairs(recipe["solids"]) do
for l, w in pairs(v.effects) do
        out[ingredient] = amount
if w.id ~= "SatiateHunger" and w.id ~= "SatiateThirst" then
    end
return "1"
    return out
end
end
end
return ""
end
end


function p.geneffects(frame, chem)
function getmicrowaverecipereagents(frame, recipe) -- should not be invoked
if chem == nil then
    local out = {}
chem = frame.args[1]
    for ingredient, amount in pairs(recipe["reagents"]) do
end
        out[ingredient] = amount
local met = p.chem[chem].metabolisms
    end
if met == nil then
    return out
return ""
end
local out = ""
for k, v in pairs(met) do
out = out .. "<b>" .. k .. "</b> (" .. v.rate .. " единиц в секунду)\n" .. p.geneffectlist(v.effects, frame, v.rate)
end
return out
end
end


function p.geneffectlist(effects, frame, rate)
function p.buildmicrowaverecipebox(frame) -- {{#invoke:Meals Lookup|buildmicrowaverecipebox|MicrowaveRecipeID}}
local out = ""
    local out = ""
for l, w in pairs(effects) do
    local id = frame.args[1]:gsub(' ', '')
-- Popup Message is ignored on purpose
    local recipe = getrecipe(frame, "microwaveRecipes", id)
if w.id == "HealthChange" then
    local solids = buildsolids(frame, getmicrowaverecipesolids(frame, recipe))
out = out .. ":" .. p.genhealthchange(w, rate, frame) .. "\n"
    local reagents = buildreagents(frame, getmicrowaverecipereagents(frame, recipe))
elseif w.id == "AdjustReagent" then
    out = frame:preprocess("{{Recipe Box" ..
out = out .. ":" .. p.genadjustreagent(w, rate, frame) .. "\n"
        "|name={{#invoke:Entity Lookup|getname|" .. recipe["result"] .. "}}" ..
elseif w.id == "FlammableReaction" then
        "|component-1=" .. solids .. "\n" .. reagents ..
out = out .. ":" .. p.genflammablereaction(w, frame) .. "\n"
        "|transformer={{Recipe Transformers|microwaveRecipes|" .. recipe["time"] .. "}}" ..
elseif w.id == "AdjustTemperature" then
        "|result=" ..
out = out .. ":" .. p.genadjusttemperature(w, frame) .. "\n"
        frame:preprocess("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
elseif w.id == "GenericStatusEffect" then
            recipe["result"] .. "}}|image=" .. getimage(frame, recipe["result"]) .. "}}") ..
out = out .. ":" .. p.gengenericstatuseffect(w, frame) .. "\n"
        "}}")
elseif w.id == "ExplosionReactionEffect" then
    return out
out = out .. ":" .. p.genexplosionreactioneffect(w, frame) .. "\n"
elseif w.id == "FoamAreaReactionEffect" then
out = out .. ":" .. p.genfoamareareactioneffect(w, frame) .. "\n"
elseif w.id == "SmokeAreaReactionEffect" then
out = out .. ":" .. p.gensmokeareareactioneffect(w, frame) .. "\n"
elseif w.id == "ModifyBleedAmount" then
out = out .. ":" .. p.genmodifybleedamount(w, frame) .. "\n"
end
end
return out
end
end


function p.gensmokeareareactioneffect(r, frame)
function p.buildmicrowaverecipes(frame)
if r.conditions ~= nil then
    local out = ""
conds = p.genconds(r.conditions, frame)
    for id in pairs(getrecipesfromtype(frame, "microwaveRecipes")) do
end
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildmicrowaverecipebox|" .. id .. "}}") .. "\n"
return frame:expandTemplate{ title = "SmokeAreaReactionEffect", args = { when = conds, prob = r.probability }}
    end
    return out
end
end


function p.genfoamareareactioneffect(r, frame)
--#endregion microwaveRecipes
if r.conditions ~= nil then
 
conds = p.genconds(r.conditions, frame)
--#region sliceableRecipes
end
 
return frame:expandTemplate{ title = "FoamAreaReactionEffect", args = { when = conds, prob = r.probability }}
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
end


function p.genexplosionreactioneffect(r, frame)
function p.buildslicerecipes(frame)
if r.conditions ~= nil then
    local out = ""
conds = p.genconds(r.conditions, frame)
    for id in pairs(getrecipesfromtype(frame, "sliceableRecipes")) do
end
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildslicerecipebox|" .. id .. "}}") .. "\n"
return frame:expandTemplate{ title = "ExplosionReactionEffect", args = { when = conds, prob = r.probability }}
    end
    return out
end
end


function p.gengenericstatuseffect(r, frame)
--#endregion sliceableRecipes
if r.conditions ~= nil then
 
conds = p.genconds(r.conditions, frame)
--#region grindableRecipes
end
 
return frame:expandTemplate{ title = "GenericStatusEffect", args = { key = r.Key, type = r.Type, time = r.Time, refresh = r.Refresh, when = conds, prob = r.probability }}
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
end


function p.genadjusttemperature(r, frame)
function p.buildgrindrecipes(frame)
if r.conditions ~= nil then
    local out = ""
conds = p.genconds(r.conditions, frame)
    for id in pairs(getrecipesfromtype(frame, "grindableRecipes")) do
end
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildgrindrecipebox|" .. id .. "}}") .. "\n"
return frame:expandTemplate{ title = "AdjustTemperature", args = { amount = r.Amount, when = conds, prob = r.probability }}
    end
    return out
end
end


function p.genflammablereaction(r, frame)
--#endregion grindableRecipes
if r.conditions ~= nil then
 
conds = p.genconds(r.conditions, frame)
--#region heatableRecipes
end
 
return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
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
end


function p.genflammablereaction(r, frame)
function p.buildheatrecipes(frame)
if r.conditions ~= nil then
    local out = ""
conds = p.genconds(r.conditions, frame)
    for id in pairs(getrecipesfromtype(frame, "heatableRecipes")) do
end
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildheatrecipebox|" .. id .. "}}") .. "\n"
return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
    end
    return out
end
end


function p.genadjustreagent(r, rate, frame)
--#endregion heatableRecipes
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "AdjustReagent", args = { amount = r.Amount, reagent = r.Reagent, when = conds, prob = r.probability }}
end


function p.genmodifybleedamount(r, frame)
--#region toolmadeRecipes
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "ModifyBleedAmount", args = { amount = r.Amount, when = conds, prob = r.probability }}
end


function p.genhealthchange(h, rate, frame)
function p.buildtoolmaderecipebox(frame) -- {{#invoke:Meals Lookup|buildtoolmaderecipebox|ToolmadeRecipeID}}
local healst = {}
    local out = ""
local dealst = {}
    local id = frame.args[1]:gsub(' ', '')
local r = 1.0 / rate
    local recipe = getrecipe(frame, "toolmadeRecipes", id)
if h.damage.types ~= nil then
    local transformer = "toolmadeRecipes" .. recipe["tool"]
for k, v in pairs(h.damage.types) do
    out = frame:preprocess("{{Recipe Box" ..
if v < 0 then
        "|name={{#invoke:Entity Lookup|getname|" .. recipe["result"] .. "}}" ..
healst[k] = v * r
        "|component-1=" ..
else
        frame:preprocess("{{Recipe Component|item={{#invoke:Entity Lookup|getname|" ..
dealst[k] = v * r
            recipe["input"] .. "}}|image=" .. getimage(frame, recipe["input"]) .. "}}") ..
end
        "|transformer={{Recipe Transformers|" .. transformer .. "}}" ..
end
        "|result=" ..
end
        frame:preprocess("{{Result Component|item={{#invoke:Entity Lookup|getname|" ..
            recipe["result"] .. "}}|image=" .. getimage(frame, recipe["result"]) .. "}}") ..
if h.damage.groups ~= nil then
        "}}")
for k, v in pairs(h.damage.groups) do
    return out
if v < 0 then
healst[k] = v * r
else
dealst[k] = v * r
end
end
end
local heals = hchangelist(healst, frame)
local deals = hchangelist(dealst, frame)
local conds = nil
if h.conditions ~= nil then
conds = p.genconds(h.conditions, frame)
end
return frame:expandTemplate{ title = "HealthChange", args = { heals = heals, deals = deals, when = conds, prob = h.probability }}
end
end


function hchangelist(l, frame)
function p.buildtoolmaderecipes(frame)
out = ""
    local out = ""
local len = tablelength(l)
    for id in pairs(getrecipesfromtype(frame, "toolmadeRecipes")) do
local i = 0
        out = out .. frame:preprocess("{{#invoke:Meals Lookup|buildtoolmaderecipebox|" .. id .. "}}") .. "\n"
for k, v in pairs(l) do
    end
i = i + 1
    return out
if len == i and i ~= 1 then
out = out .. ", and "
elseif i ~= 1 then
out = out .. ", "
end
out = out .. hchange(k, v, frame)
end
return out
end
end


-- So we can make it fancy later
--#endregion toolmadeRecipes
function hchange(ty, amnt, frame)
return frame:expandTemplate{ title = "HealthModifier", args = { adj = amnt, kind = ty } }
end


function p.genconds(conds, frame)
--#region mixableRecipes
out = ""
local len = tablelength(conds)
local i = 0
for k, v in pairs(conds) do
i = i + 1
if len == i and i ~= 1 then
out = out .. ", and "
elseif i ~= 1 then
out = out .. ", "
end
out = out .. p.gencond(v, frame)
end
return out
end


function p.gencond(c, frame)
function getchemicalreagents(recipe) -- should not be invoked
if c.id == "TotalDamage" then
    local out = {}
return frame:expandTemplate{ title = "TotalDamage", args = { min = c.Min, max = c.Max } }
    for ingredient, data in pairs(recipe["reactants"]) do
elseif c.id == "ReagentThreshold" then
        out[ingredient] = data["amount"]
return frame:expandTemplate{ title = "ReagentThreshold", args = { min = c.Min, max = c.Max, reagent = c.Reagent } }
    end
elseif c.id == "OrganType" then
    return out
return frame:expandTemplate{ title = "OrganType", args = { shouldhave = c.ShouldHave, type = c.Type } }
elseif c.id == "Temperature" then
return frame:expandTemplate{ title = "Temperature", args = {  min = c.Min, max = c.Max } }
end
return ""
end
end


function tablelength(T)
function p.buildmixablerecipebox(frame) -- {{#invoke:Meals Lookup|buildmixablerecipebox|MixableRecipeID}}
  local count = 0
    local out = ""
  for _ in pairs(T) do count = count + 1 end
    local id = frame.args[1]:gsub(' ', '')
  return count
    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
end


function has_value(tab, val)
function p.buildixablerecipes(frame)
     for index, value in ipairs(tab) do
    local out = ""
         if value[1] == val then
     for id in pairs(getrecipesfromtype(frame, "mixableRecipes")) do
            return true
         out = out .. frame:preprocess("{{#invoke:Sandbox|buildmixablerecipebox|" .. id .. "}}") .. "\n"
        end
     end
     end
    return out
end


    return false
--#endregion mixableRecipes
end


function strsplit(inputstr, seperator)
--#region dishes
        if seperator == nil then
function p.soups(frame)
                seperator = ","
    local out = ""
        end
    return out
        local t={}
        for str in string.gmatch(inputstr, "([^"..seperator.."]+)") do
                table.insert(t, str)
        end
        return t
end
end
--#endregion


function p.render_chemicals(frame)
local result = ""
local group = frame.args.group
local params
local prototype
for k in pairs(p.chem) do
prototype = p.chem[k]
if group == nil or p.chem[k].group == group then
params = {}
params.name = prototype.name
params.description = prototype.desc .. " На вид " .. prototype.physicalDesc .. "."
--туду
-- Рецепты
-- Эффекты
result = result .. frame:expandTemplate{ title = "ChemRow", args = params}
end
end


return result
-- 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
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

Текущая версия от 13:57, 12 августа 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

function p.getPagesInCategory()
    local categoryName = "Викиделы"  -- Задайте название категории здесь
    local categoryPages = {}
    
    for page in mw.parse.categoryPages(categoryName) do
        table.insert(categoryPages, page.title)
    end

    if #categoryPages == 0 then
        return "Нет страниц в категории '" .. categoryName .. "'."
    end

    local result = "Страницы в категории '" .. categoryName .. "':\n"
    for _, title in ipairs(categoryPages) do
        result = result .. "* [[ " .. title .. " ]]\n"
    end

    return result
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