Модуль:tableofchemicals
| Строка 22: | Строка 22: | ||
end | end | ||
-- | -- Если нет продуктов, пропускаем эту реакцию | ||
if mainProduct then | if mainProduct == nil then | ||
-- ничего не делаем, переходим к следующей итерации | |||
else | |||
-- Заполняем данные для колонки "Вещество" | |||
templateArgs.id = mainProduct.id | templateArgs.id = mainProduct.id | ||
templateArgs.name = mainProduct.data.name | templateArgs.name = mainProduct.data.name | ||
| Строка 29: | Строка 32: | ||
templateArgs.textColor = mainProduct.data.textColor | templateArgs.textColor = mainProduct.data.textColor | ||
templateArgs.amount = mainProduct.amount | templateArgs.amount = mainProduct.amount | ||
local reactantChemData = p.chem[reactantId] | -- Ингредиенты (реагенты) | ||
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 | end | ||
templateArgs.reactants = table.concat(reactants, "<br>") | |||
-- Результат (все продукты, кроме первого, и эффекты) | |||
local results = {} | |||
local productTemplate = "%s [[#chem_%s|%s]]" | |||
local isFirst = true | |||
for productId, productAmount in pairs(reactPrototype.products) do | |||
if isFirst then | |||
isFirst = false | |||
else | |||
local productChemData = p.chem[productId] | |||
local productText = string.format(productTemplate, productAmount, productChemData.id, productChemData.name) | |||
table.insert(results, productText) | |||
end | |||
end | end | ||
-- Эффекты реакции | |||
if tablelength(reactPrototype.effects) then | |||
for _, effect in pairs(reactPrototype.effects) do | |||
if effect.description ~= "" then | |||
table.insert(results, effect.description) | |||
end | |||
end | end | ||
end | end | ||
templateArgs.results = table.concat(results, "<br>") | |||
-- Действие | |||
templateArgs.actions = getActions(reactPrototype) | |||
local template = "Строка_реакции" | |||
out = out .. frame:expandTemplate{ title = template, args = templateArgs} | |||
end | end | ||
end | end | ||
return out | return out | ||