Модуль: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
end
-- Реагенты
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)
local reactants = {}
if reactantValue.catalyst then
local reactantTemplate = "%s [[#chem_%s|%s]]"
reactantText = reactantText .. " (катализатор)"
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
table.insert(reactants, reactantText)
templateArgs.reactants = table.concat(reactants, "<br>")
end
templateArgs.reactants = table.concat(reactants, "<br>")
-- Результат (все продукты, кроме первого, и эффекты)
local results = {}
-- Продукты (все, кроме первого, т.к. первый уже в первом столбце)
local productTemplate = "%s [[#chem_%s|%s]]"
local products = {}
local isFirst = true
local productTemplate = "%s [[#chem_%s|%s]]"
local isFirst = true
for productId, productAmount in pairs(reactPrototype.products) do
if isFirst then
for productId, productAmount in pairs(reactPrototype.products) do
isFirst = false
if isFirst then
else
isFirst = false
local productChemData = p.chem[productId]
else
local productText = string.format(productTemplate, productAmount, productChemData.id,  productChemData.name)
local productChemData = p.chem[productId]
table.insert(results, productText)
local productText = string.format(productTemplate, productAmount, productChemData.id,  productChemData.name)
end
table.insert(products, productText)
end
end
end
-- Эффекты реакции
-- Эффекты реакции
if tablelength(reactPrototype.effects) then
if tablelength(reactPrototype.effects) then
for _, effect in pairs(reactPrototype.effects) do
for _, effect in pairs(reactPrototype.effects) do
if effect.description ~= "" then
if effect.description ~= "" then
table.insert(results, effect.description)
table.insert(products, 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
templateArgs.products = table.concat(products, "<br>")
templateArgs.actions = getActions(reactPrototype)
local template = "Строка_реакции"
out = out .. frame:expandTemplate{ title = template, args = templateArgs}
end
end
return out
return out