Модуль:TableOfChemicals: различия между версиями
Нет описания правки |
Нет описания правки |
||
| Строка 5: | Строка 5: | ||
p.fillReactTable = function(frame) | p.fillReactTable = function(frame) | ||
local out = "{|" | |||
out = attachAsNewLine(out, "!") | |||
for _, reactPrototype in pairs(p.react) do | |||
if tablelength(reactPrototype.effects) ~= 0 then | |||
local reactants = {} | |||
local reactantTemplate = "%s [[#chem_%s|%s]]" | |||
for reactantId, reactantValue in pairs(reactPrototype.reactants) do | |||
local reactantChemData = p.chem[reactantId] | |||
local reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.id, reactantChemData.name) | |||
if reactantValue.catalyst then | |||
reactantText = reactantText .. " (катализатор)" | |||
end | |||
table.insert(reactants, reactantText) | |||
end | |||
templateArgs.reactants = table.concat(reactants, "<br>") | |||
local products = {} | |||
local productTemplate = "%s [[#chem_%s|%s]]" | |||
for productId, productAmount in pairs(reactPrototype.products) do | |||
local productChemData = p.chem[productId] | |||
local productText = string.format(productTemplate, productAmount, productChemData.id, productChemData.name) | |||
table.insert(products, productText) | |||
end | |||
-- Эффекты реакции | |||
if tablelength(reactPrototype.effects) then | |||
for _, effect in pairs(reactPrototype.effects) do | |||
if effect.description ~= "" then | |||
table.insert(products, effect.description) | |||
end | |||
end | |||
end | |||
templateArgs.products = table.concat(products, "<br>") | |||
templateArgs.actions = getActions(reactPrototype) | |||
local template = "Строка_реакции" | |||
out = out .. frame:expandTemplate{ title = template, args = templateArgs} | |||
end | |||
end | |||
end | end | ||