Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

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

Материал из Space Stories Wiki
Нет описания правки
Метка: отменено
Нет описания правки
Метка: ручная отмена
 
Строка 1: Строка 1:
local prototypes = mw.loadData("Module:Chemistry Lookup/data")
local p = {}
local p = {}
local mw = mw
p.chem = prototypes.chem
local html = mw.html
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


local function getArgs(frame)
function p.readscalarreact(frame)
    if type(frame) == "table" and frame.args then return frame.args end
if p.react[frame.args[1]][frame.args[2]] ~= nil then
    return mw.getCurrentFrame():getParent().args or {}
return mw.text.nowiki(p.react[frame.args[1]][frame.args[2]])
else
return ""
end
end
end


local function splitLines(s)
function p.getcolor(frame)
    local t = {}
return mw.text.nowiki(p.chem[frame.args[1]].color:sub(1, 7))
    if not s then return t end
end
    for line in mw.text.gsplit(s, "\n") do
 
        line = mw.text.trim(line)
function p.gettextcolor(frame)
        if line ~= "" then table.insert(t, line) end
local basecol = p.chem[frame.args[1]].color
    end
local red = tonumber(basecol:sub(2, 3), 16)
    return t
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
end


local function parseLineToItem(l)
function p.buildrecipes(frame)
    local name, qty = mw.ustring.match(l, "^(.*)%s*%[%s*([%d,%.]+)%s*%]%s*$")
local chem = frame.args[1]
    if not name then name = l; qty = "1" end
local out = ""
    return { name = mw.text.trim(name), qty = qty or "1" }
for id, recipe in pairs(p.chem[chem].recipes) do
out = out .. p.buildreaction(frame, recipe)
end
return out
end
end


local function parseRecipeString(recipeStr)
function p.buildreactionext(frame)
    if not recipeStr or recipeStr == "" then return {} end
local react = frame.args[1]
    local lines = splitLines(recipeStr)
return p.buildreaction(frame, react)
    local steps = {}
    local currentInputs = {}
    local i = 1
    while i <= #lines do
        local line = lines[i]
        local lower = mw.ustring.lower(line)
        if lower:find("смеш") then
            if #currentInputs > 0 then
                local outputs = {}
                i = i + 1
                while i <= #lines do
                    local nextLine = lines[i]
                    local nextLower = mw.ustring.lower(nextLine)
                    if nextLower:find("смеш") then break end
                    table.insert(outputs, parseLineToItem(nextLine))
                    i = i + 1
                end
                table.insert(steps, {
                    inputs = currentInputs,
                    outputs = outputs,
                    action = mw.text.trim(line)
                })
                currentInputs = {}
            else
                i = i + 1
            end
        else
            table.insert(currentInputs, parseLineToItem(line))
            i = i + 1
        end
    end
    if #currentInputs > 0 then
        table.insert(steps, { inputs = currentInputs, outputs = {}, action = "" })
    end
    return steps
end
end


local FILE_PATTERN = "(%[%[File:[^]]+%]%])"
function p.buildreaction(frame, react)
local data = p.react[react]
local dest = "Chemistry"
local args = {}
local i = 0
args["prototype"] = frame.args[1]
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


local function buildRecipeStepHtml(rec)
return frame:expandTemplate{ title = "Chem Box Recipe", args = args}
    if not rec or (#rec.inputs == 0 and #rec.outputs == 0) then return nil end
end


    local inner = html.create("div"):addClass("chem-recipe")
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


    local inputsDiv = html.create("div"):addClass("recipe-inputs")
function p.checksatiateshunger(frame)
    for _, it in ipairs(rec.inputs) do
local chem = frame.args[1]
        local item = inputsDiv:tag("div"):addClass("recipe-item")
local met = p.chem[chem].metabolisms
        item:wikitext('[[File:Beaker.png|class=chem-beaker]] ' .. it.name .. ' [' .. it.qty .. ']')
if met == nil then
    end
return ""
    inner:node(inputsDiv)
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


    if rec.action and rec.action ~= "" then
function p.geneffects(frame, chem)
        local actionDiv = inner:tag("div"):addClass("recipe-action")
if chem == nil then
        local content = actionDiv:tag("div"):addClass("recipe-action-content")
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


        local sprite = '[[File:Beaker.png|class=chem-beaker]]'
function p.geneffectlist(effects, frame, rate)
        local actionText = rec.action
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


        local customSprite = mw.ustring.match(actionText, FILE_PATTERN)
function p.gensmokeareareactioneffect(r, frame)
        if customSprite then
if r.conditions ~= nil then  
            sprite = customSprite
conds = p.genconds(r.conditions, frame)
            actionText = mw.text.trim(mw.ustring.gsub(actionText, FILE_PATTERN, ""))
end
        end
return frame:expandTemplate{ title = "SmokeAreaReactionEffect", args = { when = conds, prob = r.probability }}
end


        content:tag("div"):addClass("action-sprite"):wikitext(sprite)
function p.genfoamareareactioneffect(r, frame)
        content:tag("div"):addClass("action-text"):wikitext(actionText)
if r.conditions ~= nil then
    end
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "FoamAreaReactionEffect", args = { when = conds, prob = r.probability }}
end


    local outputsDiv = html.create("div"):addClass("recipe-outputs")
function p.genexplosionreactioneffect(r, frame)
    for _, it in ipairs(rec.outputs) do
if r.conditions ~= nil then
        local item = outputsDiv:tag("div"):addClass("recipe-item")
conds = p.genconds(r.conditions, frame)
        item:wikitext('[[File:Beaker.png|class=chem-beaker]] ' .. it.name .. ' [' .. it.qty .. ']')
end
    end
return frame:expandTemplate{ title = "ExplosionReactionEffect", args = { when = conds, prob = r.probability }}
    inner:node(outputsDiv)
end


    return inner
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, temperature = r.Temperature, ammount = r.Ammount, deleteReagent = r.DeleteReagent , refresh = r.Refresh, when = conds, prob = r.probability }}
end
end


local function buildEffectsHtml(effects)
function p.genadjusttemperature(r, frame)
    if not effects or effects == "" or effects == "Нет" then return nil end
if r.conditions ~= nil then  
    local container = html.create("div"):addClass("chem-effects-block")
conds = p.genconds(r.conditions, frame)
    local heading = html.create("div"):addClass("chem-heading"):attr("data-kind", "effects")
end
    local hcontent = heading:tag("div"):addClass("chem-heading-content")
return frame:expandTemplate{ title = "AdjustTemperature", args = { amount = r.Amount, when = conds, prob = r.probability }}
    hcontent:tag("span"):addClass("heading-text"):wikitext("Эффекты")
end
    hcontent:tag("span"):addClass("collapse-btn"):wikitext("развернуть")
    container:node(heading)


    local collapsible = html.create("div"):addClass("collapsible collapsed"):attr("data-kind", "effects")
function p.genflammablereaction(r, frame)
    local inner = html.create("div"):addClass("chem-effects")
if r.conditions ~= nil then
    for effect in mw.text.gsplit(effects, "[;\n]") do
conds = p.genconds(r.conditions, frame)
        effect = mw.text.trim(effect)
end
        if effect ~= "" then
return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
            inner:tag("div"):addClass("chem-effect-line"):wikitext(effect)
        end
    end
    collapsible:node(inner)
    container:node(collapsible)
    return container
end
end


function p.card(frame)
function p.genflammablereaction(r, frame)
    local args = getArgs(frame)
if r.conditions ~= nil then
    local name = args.name or ""
conds = p.genconds(r.conditions, frame)
    local color = args.color or "#8cf"
end
    local border = args.border or "#444"
return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
    local desc = args.desc or ""
end


    local variants = {}
function p.genadjustreagent(r, rate, frame)
    local i = 1
if r.conditions ~= nil then
    while true do
conds = p.genconds(r.conditions, frame)
        local key = i == 1 and "recipe" or ("recipe" .. i)
end
        local recipeStr = args[key]
return frame:expandTemplate{ title = "AdjustReagent", args = { amount = r.Amount, reagent = r.Reagent, when = conds, prob = r.probability }}
        if not recipeStr then break end
end
        local steps = parseRecipeString(recipeStr)
        if #steps > 0 then
            table.insert(variants, {id = i, steps = steps})
        end
        i = i + 1
    end


    local container = html.create("div"):addClass("chem-card")
function p.genmodifybleedamount(r, frame)
    container:attr("style", "border-color:" .. border .. "; --card-accent:" .. color)
if r.conditions ~= nil then
    container:tag("div"):addClass("chem-name-header"):wikitext(name)
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "ModifyBleedAmount", args = { amount = r.Amount, when = conds, prob = r.probability }}
end


    if #variants > 0 then
function p.genhealthchange(h, rate, frame)
        local recipeBlock = html.create("div"):addClass("chem-recipe-block")
local healst = {}
        local heading = html.create("div"):addClass("chem-heading"):attr("data-kind", "recipe")
local dealst = {}
        local hcontent = heading:tag("div"):addClass("chem-heading-content")
local r = 1.0 / rate
        hcontent:tag("span"):addClass("heading-text"):wikitext("Рецепты")
if h.damage.types ~= nil then
        hcontent:tag("span"):addClass("collapse-btn"):wikitext("развернуть")
for k, v in pairs(h.damage.types) do
        recipeBlock:node(heading)
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


        local collapsible = html.create("div"):addClass("collapsible collapsed"):attr("data-kind", "recipe")
function hchangelist(l, frame)
        local stepsContainer = html.create("div"):addClass("chem-recipe-steps")
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


        for vidx, variant in ipairs(variants) do
-- So we can make it fancy later
            if #variants > 1 then
function hchange(ty, amnt, frame)
                local varHeader = stepsContainer:tag("div"):addClass("recipe-variant-header")
return frame:expandTemplate{ title = "HealthModifier", args = { adj = amnt, kind = ty } }
                varHeader:wikitext("Вариант " .. vidx)
end
            end


            for _, rec in ipairs(variant.steps) do
function p.genconds(conds, frame)
                local step = buildRecipeStepHtml(rec)
out = ""
                if step then stepsContainer:node(step) end
local len = tablelength(conds)
            end
local i = 0
        end
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


        collapsible:node(stepsContainer)
function p.gencond(c, frame)
        recipeBlock:node(collapsible)
if c.id == "TotalDamage" then
        container:node(recipeBlock)
return frame:expandTemplate{ title = "TotalDamage", args = { min = c.Min, max = c.Max } }
    end
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


    local effectsBlock = buildEffectsHtml(args.effects)
function tablelength(T)
    if effectsBlock then container:node(effectsBlock) end
  local count = 0
  for _ in pairs(T) do count = count + 1 end
  return count
end


     if desc ~= "" then
function has_value(tab, val)
         container:tag("div"):addClass("chem-desc"):wikitext(desc)
     for index, value in ipairs(tab) do
        if value[1] == val then
            return true
         end
     end
     end


     return tostring(container)
     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
end


return p
return p

Текущая версия от 13:24, 4 апреля 2026

Для документации этого модуля может быть создана страница Модуль:Chemistry Lookup/doc

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
	args["prototype"] = frame.args[1]
	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, temperature = r.Temperature, ammount = r.Ammount, deleteReagent = r.DeleteReagent , 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