Модуль:TableOfChemicals

Материал из Space Station 14 Вики

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

p = {}

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

p.fillTable = function(frame)
	local out = {}
	
	local out = ""
	local group = frame.args.group
	--local chemPrototype
	--local reactPrototype
	local templateArgs = {}
	for _, chemPrototype in pairs(p.chem) do
		
		--chemPrototype = p.chem[chemPrototypeKey]
		
		if group == nil or chemPrototype.group == group then
			
			--Формирование таблицы для передачи в шаблоны
			templateArgs.name = chemPrototype.name
			templateArgs.description = chemPrototype.desc .. " На вид " .. chemPrototype.physicalDesc .. "."
			templateArgs.effects = getEffects(chemPrototype.id)
			
			templateArgs.recipes_count = tablelength(chemPrototype.recipes)
			local firstReact = true
			for _, reactId in pairs(chemPrototype.recipes) do
				--reactPrototype = p.react[reactPrototypeKey]
				
				local reactPrototype = p.react[reactId]
				
				local reactants = {}
				for reactantId, reactantValue in pairs(reactPrototype.reactants) do
					
					local reactantChemData = p.chem[reactantId]
					local reactantText = reactantValue.amount .. " " .. reactantChemData.name 
					table.insert(reactants, reactantText)
				end
				templateArgs.reactants = table.concat(reactants, "<br>")
				
				local products = {}
				for productId, productAmount in pairs(reactPrototype.products) do
					
					local productChemData = p.chem[productId]
					local productText = productAmount .. " " .. productChemData.name 
					table.insert(products, productText)
				end
				templateArgs.products = table.concat(reactants, "<br>")
				
				templateArgs.action = "смешать"
				
				local template = "Строка_химического_вещества"
				if firstReact then
					template = "Первая_строка_химического_вещества"
					firstReact = false
				end
				
				out = out .. frame:expandTemplate{ title = template, args = templateArgs}
			end
			
		end
	end
	
	return out
	
end

p.fillEffectsTable = function(frame)
	local out = {}

	for idx = 1, 5 do
		table.insert(out, idx)
	end

	return "effects"
end

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

function getEffects(id)
  return ""
end

return p