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.prototypes = prototypes
p.chem = prototypes.chem
p.react = prototypes.react


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


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


Line 15: Line 16:
local out = ""
local out = ""
local group = frame.args[1]
local group = frame.args[1]
for k in pairs(prototypes) do
for k in pairs(p.chem) do
if prototypes[k].group == group then
if p.chem[k].group == group then
out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
out = out .. frame:expandTemplate{ title = "Chembox", args = { prototype = k }}
end
end

Revision as of 05:13, 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

return p