Module:Chemistry Lookup: Difference between revisions

From Space Station 14 Wiki
No edit summary
No edit summary
Line 2: Line 2:


local p = {}
local p = {}
p.chem = prototypes[1]
p.chem = prototypes.chem
p.react = prototypes[2]
p.react = prototypes.react


function p.readscalar(frame)
function p.readscalar(frame)
Line 76: Line 76:
end
end
return ""
return ""
end
function p.gethealthbenefits(chem)
local met = p.chem[chem].metabolisms
end
end


return p
return p

Revision as of 21:05, 18 December 2021

Documentation for this module may be created at Module:Chemistry Lookup/doc

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

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

function p.readscalar(frame)
	return mw.text.nowiki(p.chem[frame.args[1]][frame.args[2]])
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 }}
		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
		local data = p.react[recipe]
		local args = {}
		local i = 0
		for k,v in pairs(data.reactants) do
			i = i + 1
			args["component-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = p.chem[k].name, prototype = k, amount = v.amount }}
		end
		i = 0
		for k,v in pairs(data.products) do
			i = i + 1
			args["result-" .. i] = frame:expandTemplate{ title = "Chem Recipe Component", args = { reagent = p.chem[k].name, prototype = k, amount = v }}
		end

		out = out .. frame:expandTemplate{ title = "Chem Box Recipe", args = args }
	end
	return out
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.gethealthbenefits(chem)
	local met = p.chem[chem].metabolisms
end

return p