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

Материал из Space Station 14 Вики
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
local prototypes = mw.loadData("Module:Entity Lookup/data")
local prototypes = mw.loadData("Module:Chemistry Lookup/data")


local p = {}
local p = {}
p.entities = prototypes.entities
p.chem = prototypes.chem
p.react = prototypes.react
p.groupDirection = prototypes.groupDirection


function p.readscalar(frame)
return mw.text.nowiki(p.chem[frame.args[1]][frame.args[2]])
end
function p.readscalarreact(frame)
if p.react[frame.args[1]][frame.args[2]] ~= nil then
return mw.text.nowiki(p.react[frame.args[1]][frame.args[2]])
else
return ""
end
end
function p.getcolor(frame)
return mw.text.nowiki(p.chem[frame.args[1]].color:sub(1, 7))
end
function p.gettextcolor(frame)
local basecol = p.chem[frame.args[1]].color
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
function p.hasrecipe(frame)
return p.chem[frame.args[1]]["recipes"][1] ~= nil
end
function p.buildboxes(frame)
local out = ""
local group = frame.args[1]
for k in pairs(p.chem) do
if p.chem[k].group == group then
out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
elseif group == nil then
out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
end
end
return out
end
function p.buildreactboxes(frame)
local out = ""
for k in pairs(p.react) do
if tablelength(p.react[k].effects) ~= 0 then
out = out .. frame:expandTemplate{ title = "Reactionbox", args = { reaction = k }}
end
end
return out
end
function p.buildrecipes(frame)
local chem = frame.args[1]
local out = ""
for id, recipe in pairs(p.chem[chem].recipes) do
out = out .. p.buildreaction(frame, recipe)
end
return out
end
function p.buildreactionext(frame)
local react = frame.args[1]
return p.buildreaction(frame, react)
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 }
end
function p.checksatiatesthirst(frame)
local chem = frame.args[1]
local met = p.chem[chem].metabolisms
if met == nil then
return ""
end
for k, v in pairs(met) do
for l, w in pairs(v.effects) do
if w.id == "SatiateThirst" then
return "1"
end
end
end
return ""
end
function p.checksatiateshunger(frame)
local chem = frame.args[1]
local met = p.chem[chem].metabolisms
if met == nil then
return ""
end
for k, v in pairs(met) do
for l, w in pairs(v.effects) do
if w.id == "SatiateHunger" then
return "1"
end
end
end
return ""
end
function p.haseffects(frame)
local chem = frame.args[1]
local met = p.chem[chem].metabolisms
if met == nil then
return ""
end
for k, v in pairs(met) do
for l, w in pairs(v.effects) do
if w.id ~= "SatiateHunger" and w.id ~= "SatiateThirst" then
return "1"
end
end
end
return ""
end
function p.geneffects(frame, chem)
if chem == nil then
chem = frame.args[1]
end
local met = p.chem[chem].metabolisms
if met == nil then
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
function p.geneffectlist(effects, frame, rate)
local out = ""
for l, w in pairs(effects) do
-- Popup Message is ignored on purpose
if w.id == "HealthChange" then
out = out .. ":" .. p.genhealthchange(w, rate, frame) .. "\n"
elseif w.id == "AdjustReagent" then
out = out .. ":" .. p.genadjustreagent(w, rate, frame) .. "\n"
elseif w.id == "FlammableReaction" then
out = out .. ":" .. p.genflammablereaction(w, frame) .. "\n"
elseif w.id == "AdjustTemperature" then
out = out .. ":" .. p.genadjusttemperature(w, frame) .. "\n"
elseif w.id == "GenericStatusEffect" then
out = out .. ":" .. p.gengenericstatuseffect(w, frame) .. "\n"
elseif w.id == "ExplosionReactionEffect" then
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
function p.gensmokeareareactioneffect(r, frame)
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "SmokeAreaReactionEffect", args = { when = conds, prob = r.probability }}
end


function p.xd(frame)
function p.genfoamareareactioneffect(r, frame)
    -- body
if r.conditions ~= nil then
    local out = frame:expandTemplate{ title = "Temperature", args = { min = 322, max = "Infinity" }}
conds = p.genconds(r.conditions, frame)
    return out
end
return frame:expandTemplate{ title = "FoamAreaReactionEffect", args = { when = conds, prob = r.probability }}
end
end


function p.tests(frame)
function p.genexplosionreactioneffect(r, frame)
    local out = ""
if r.conditions ~= nil then
    local title = mw.title.new( frame.args[1] )
conds = p.genconds(r.conditions, frame)
    local temp = title.file.exists
end
    return temp
return frame:expandTemplate{ title = "ExplosionReactionEffect", args = { when = conds, prob = r.probability }}
end
end


function p.textreplacement(frame)
function p.gengenericstatuseffect(r, frame)
    -- body
if r.conditions ~= nil then  
    local meta = frame.args["Мета"]
conds = p.genconds(r.conditions, frame)
    local out = ""
end
    if meta == nil then do
return frame:expandTemplate{ title = "GenericStatusEffect", args = { key = r.Key, type = r.Type, time = r.Time, refresh = r.Refresh, when = conds, prob = r.probability }}
        meta = "64x64px|link="
        meta = meta:gsub(',', '|')
    end else
        meta = "Uvi"
    end
    out = out .. meta
    return out
end
end


function p.mhamstersandbox(frame)
function p.genadjusttemperature(r, frame)
    -- body
if r.conditions ~= nil then
    local out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { frame.args[1], "Нижний правый текст", "FreedomImplant", "Файл:Honks.gif" }}
conds = p.genconds(r.conditions, frame)
    return out
end
return frame:expandTemplate{ title = "AdjustTemperature", args = { amount = r.Amount, when = conds, prob = r.probability }}
end
end


function p.createtexttooltip(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|img=картиночка}}
function p.genflammablereaction(r, frame)
    local out = " "
if r.conditions ~= nil then  
    local entity = p.entities[frame.args[2]]
conds = p.genconds(r.conditions, frame)
    -- local pic = frame.args[3]
end
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
    if entity ~= nil then do
    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
    return out
end
end


function p.createtexttooltippartii(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function p.genflammablereaction(r, frame)
    local out = " "
if r.conditions ~= nil then  
    local entity = p.entities[frame.args[2]]
conds = p.genconds(r.conditions, frame)
    local pic = frame.args[3]
end
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
    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
    return out
end
end


function p.createtexttooltippartiii(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function p.genadjustreagent(r, rate, frame)
    local out = " "
if r.conditions ~= nil then  
    local entity = p.entities[frame.args[2]]
conds = p.genconds(r.conditions, frame)
    local pic = frame.args[3]
end
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
return frame:expandTemplate{ title = "AdjustReagent", args = { amount = r.Amount, reagent = r.Reagent, when = conds, prob = r.probability }}
    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 = { "xdi", frame.args[1], entity.name, entity.desc, pic=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
    return out
end
end


function p.createtexttooltippartiv(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function p.genmodifybleedamount(r, frame)
    local out = " "
if r.conditions ~= nil then  
    local entity = p.entities[frame.args[2]]
conds = p.genconds(r.conditions, frame)
    local pic = frame.args[3]
end
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
return frame:expandTemplate{ title = "ModifyBleedAmount", args = { amount = r.Amount, when = conds, prob = r.probability }}
    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 = { "xdii", frame.args[1], entity.name, frame.args[3], desc=entity.desc}}
    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
    return out
end
end


function p.createtexttooltippartv(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function p.genhealthchange(h, rate, frame)
    local out = " "
local healst = {}
    local entity = p.entities[frame.args[2]]
local dealst = {}
    local pic = frame.args[3]
local r = 1.0 / rate
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
if h.damage.types ~= nil then
    if entity ~= nil then do
for k, v in pairs(h.damage.types) do
    if frame.args[3] ~= nil then do
if v < 0 then
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
healst[k] = v * r
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args[1], entity.name, entity.desc, frame.args["Pic"] }}
else
    end else
dealst[k] = v * r
    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=]] Не найден", "Предмет не найден"}}
if h.damage.groups ~= nil then
    end
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 p.createtexttooltippartvi(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function hchangelist(l, frame)
    local out = " "
out = ""
    local entity = p.entities[frame.args[1]]
local len = tablelength(l)
    local pic = frame.args[2]
local i = 0
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
for k, v in pairs(l) do
    if entity ~= nil then do
i = i + 1
    if frame.args[3] ~= nil then do
if len == i and i ~= 1 then
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
out = out .. ", and "
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args["Текст"], entity.name, entity.desc, frame.args[3] }}
elseif i ~= 1 then
    end else
out = out .. ", "
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "xd", frame.args["Текст"],  entity.name, entity.desc}}
end
    end
out = out .. hchange(k, v, frame)
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
end
    end else
return out
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
    end
    return out
end
end


function p.createtexttooltippartvii(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
-- So we can make it fancy later
    local out = " "
function hchange(ty, amnt, frame)
    local entity = p.entities[frame.args[1]]
return frame:expandTemplate{ title = "HealthModifier", args = { adj = amnt, kind = ty } }
    local pic = frame.args[2]
    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
    return out
end
end


function p.createtexttooltippartviii(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function p.genconds(conds, frame)
    local out = " "
out = ""
    local entity = p.entities[frame.args[2]]
local len = tablelength(conds)
    local pic = frame.args[3]
local i = 0
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
for k, v in pairs(conds) do
    if entity ~= nil then do
i = i + 1
    if frame.args[3] ~= nil then do
if len == i and i ~= 1 then
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
out = out .. ", and "
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", frame.args[1], entity.name, entity.desc, frame.args[3] }}
elseif i ~= 1 then
    end else
out = out .. ", "
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", frame.args[1],  entity.name, entity.desc}}
end
    end
out = out .. p.gencond(v, frame)
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
end
    end else
return out
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1],  "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
    end
    return out
end
end


function p.createtexttooltippartix(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function p.gencond(c, frame)
    local out = " "
if c.id == "TotalDamage" then
    local entity = p.entities[frame.args[2]]
return frame:expandTemplate{ title = "TotalDamage", args = { min = c.Min, max = c.Max } }
    local pic = frame.args[3]
elseif c.id == "ReagentThreshold" then
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
return frame:expandTemplate{ title = "ReagentThreshold", args = { min = c.Min, max = c.Max, reagent = c.Reagent } }
    if entity ~= nil then do
elseif c.id == "OrganType" then
    if frame.args[3] ~= nil then do
return frame:expandTemplate{ title = "OrganType", args = { shouldhave = c.ShouldHave, type = c.Type } }
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
elseif c.id == "Temperature" then
    out =  frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lolone", entity.name, entity.desc, frame.args[3], Text=frame.args[1] }}
return frame:expandTemplate{ title = "Temperature", args = { min = c.Min, max = c.Max } }
    end else
end
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", frame.args[1], entity.name, entity.desc}}
return ""
    end
    -- {{Tooltip|Текст|[[картиночка|64x64px|left|middle|link=]] Название|Описание}}
    end else
      out = frame:expandTemplate{ title = "Tooltip", args = { frame.args[1], "[[Файл:Mousegif.gif|64x64px|left|middle|link=]] Не найден", "Предмет не найден"}}
    end
    return out
end
end


function p.createtexttooltippartx(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function tablelength(T)
    local out = " "
  local count = 0
    local entity = p.entities[frame.args[2]]
  for _ in pairs(T) do count = count + 1 end
    local pic = frame.args[3]
  return count
    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 = { "loltwo", frame.args[1], entity.name, entity.desc, pic=frame.args[3] }}
    end else
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", 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
    return out
end
end


function p.createtexttooltippartxi(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function has_value(tab, val)
    local out = " "
     for index, value in ipairs(tab) do
     local entity = p.entities[frame.args[1]]
        if value[1] == val then
    local pic = frame.args[2]
            return true
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
        end
    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 = { "lol", frame.args["Text"], entity.name, entity.desc, frame.args[2] }}
    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 false
end
end


function p.createtexttooltippartxii(frame) -- {{#invoke:Entity Lookup|createtexttooltip|Текст|ProtoID|Pic=картиночка}}
function strsplit(inputstr, seperator)
    local out = " "
        if seperator == nil then
    local entity = p.entities[frame.args[2]]
                seperator = ","
    local pic = frame.args[3]
        end
    local stats = frame:expandTemplate{ title = "Особое", args = { frame.args[2] }}
        local t={}
    if entity ~= nil then do
        for str in string.gmatch(inputstr, "([^"..seperator.."]+)") do
    if frame.args[3] ~= nil then do
                table.insert(t, str)
    pic = "[[File:" .. frame.args[3] .. "|64x64px|left|middle|link=]]"
        end
    out = frame:expandTemplate{ title = "Mhamster/sandbox", args = { "lol", frame.args[1], entity.name, entity.desc, frame.args["pic"] }}
        return t
    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
    return out
end
end


return p
return p

Версия от 23:13, 22 апреля 2024

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


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

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

function p.readscalar(frame)
	return mw.text.nowiki(p.chem[frame.args[1]][frame.args[2]])
end

function p.readscalarreact(frame)
	if p.react[frame.args[1]][frame.args[2]] ~= nil then
		return mw.text.nowiki(p.react[frame.args[1]][frame.args[2]])
	else
		return ""
	end
end

function p.getcolor(frame)
	return mw.text.nowiki(p.chem[frame.args[1]].color:sub(1, 7))
end

function p.gettextcolor(frame)
	local basecol = p.chem[frame.args[1]].color
	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

function p.hasrecipe(frame)
	return p.chem[frame.args[1]]["recipes"][1] ~= nil
end

function p.buildboxes(frame)
	local out = ""
	local group = frame.args[1]
	for k in pairs(p.chem) do
		if p.chem[k].group == group then
			out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
		elseif group == nil then
			out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
		end
	end
	return out
end

function p.buildreactboxes(frame)
	local out = ""
	for k in pairs(p.react) do
		if tablelength(p.react[k].effects) ~= 0 then
			out = out .. frame:expandTemplate{ title = "Reactionbox", args = { reaction = k }}	
		end
	end
	return out
end

function p.buildrecipes(frame)
	local chem = frame.args[1]
	local out = ""
	for id, recipe in pairs(p.chem[chem].recipes) do
		out = out .. p.buildreaction(frame, recipe)
	end
	return out
end

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

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

function p.checksatiateshunger(frame)
	local chem = frame.args[1]
	local met = p.chem[chem].metabolisms
	if met == nil then
		return ""
	end
	for k, v in pairs(met) do
		for l, w in pairs(v.effects) do
			if w.id == "SatiateHunger" then
				return "1"
			end
		end
	end
	return ""
end

function p.haseffects(frame)
	local chem = frame.args[1]
	local met = p.chem[chem].metabolisms
	if met == nil then
		return ""
	end
	for k, v in pairs(met) do
		for l, w in pairs(v.effects) do
			if w.id ~= "SatiateHunger" and w.id ~= "SatiateThirst" then
				return "1"
			end
		end
	end
	return ""
end

function p.geneffects(frame, chem)
	if chem == nil then
		chem = frame.args[1]
	end
	local met = p.chem[chem].metabolisms
	if met == nil then
		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

function p.geneffectlist(effects, frame, rate)
	local out = ""
	for l, w in pairs(effects) do
		-- Popup Message is ignored on purpose
		if w.id == "HealthChange" then
			out = out .. ":" .. p.genhealthchange(w, rate, frame) .. "\n"
		elseif w.id == "AdjustReagent" then
			out = out .. ":" .. p.genadjustreagent(w, rate, frame) .. "\n"
		elseif w.id == "FlammableReaction" then
			out = out .. ":" .. p.genflammablereaction(w, frame) .. "\n"
		elseif w.id == "AdjustTemperature" then
			out = out .. ":" .. p.genadjusttemperature(w, frame) .. "\n"
		elseif w.id == "GenericStatusEffect" then
			out = out .. ":" .. p.gengenericstatuseffect(w, frame) .. "\n"
		elseif w.id == "ExplosionReactionEffect" then
			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

function p.gensmokeareareactioneffect(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "SmokeAreaReactionEffect", args = { when = conds, prob = r.probability }}
end

function p.genfoamareareactioneffect(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "FoamAreaReactionEffect", args = { when = conds, prob = r.probability }}
end

function p.genexplosionreactioneffect(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "ExplosionReactionEffect", args = { when = conds, prob = r.probability }}
end

function p.gengenericstatuseffect(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "GenericStatusEffect", args = { key = r.Key, type = r.Type, time = r.Time, refresh = r.Refresh, when = conds, prob = r.probability }}
end

function p.genadjusttemperature(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "AdjustTemperature", args = { amount = r.Amount, when = conds, prob = r.probability }}
end

function p.genflammablereaction(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
end

function p.genflammablereaction(r, frame)
	if r.conditions ~= nil then 
		conds = p.genconds(r.conditions, frame)
	end
	return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
end

function p.genadjustreagent(r, rate, frame)
	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)
	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)
	local healst = {}
	local dealst = {}
	local r = 1.0 / rate
	if h.damage.types ~= nil then
	for k, v in pairs(h.damage.types) do
		if v < 0 then
			healst[k] = v * r
		else
			dealst[k] = v * r
		end
	end
	end
	
	if h.damage.groups ~= nil then
	for k, v in pairs(h.damage.groups) do
		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

function hchangelist(l, frame)
	out = ""
	local len = tablelength(l)
	local i = 0
	for k, v in pairs(l) do
		i = i + 1
		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

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

function p.genconds(conds, frame)
	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)
	if c.id == "TotalDamage" then
		return frame:expandTemplate{ title = "TotalDamage", args = { min = c.Min, max = c.Max } }
	elseif c.id == "ReagentThreshold" then
		return frame:expandTemplate{ title = "ReagentThreshold", args = { min = c.Min, max = c.Max, reagent = c.Reagent } }
	elseif c.id == "OrganType" then
		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

function tablelength(T)
  local count = 0
  for _ in pairs(T) do count = count + 1 end
  return count
end

function has_value(tab, val)
    for index, value in ipairs(tab) do
        if value[1] == val then
            return true
        end
    end

    return false
end

function strsplit(inputstr, seperator)
        if seperator == nil then
                seperator = ","
        end
        local t={}
        for str in string.gmatch(inputstr, "([^"..seperator.."]+)") do
                table.insert(t, str)
        end
        return t
end


return p