Модуль:tableofchemicals

Вернуться

Строка 8: Строка 8:
for _, reactPrototype in pairs(p.react) do
for _, reactPrototype in pairs(p.react) do
local templateArgs = {}
local reactants = {}
local reactantTemplate = "%s [[#chem_%s|%s]]"
-- Определяем первый продукт как основной (итоговый)
for reactantId, reactantValue in pairs(reactPrototype.reactants) do
local mainProduct = nil
for productId, productAmount in pairs(reactPrototype.products) do
local reactantChemData = p.chem[reactantId]
if mainProduct == nil then
local reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.id,  reactantChemData.name)
mainProduct = {
if reactantValue.catalyst then
id = productId,
reactantText = reactantText .. " (катализатор)"
amount = productAmount,
data = p.chem[productId]
}
end
end
table.insert(reactants, reactantText)
end
end
local templateArgs = {}
templateArgs.reactants = table.concat(reactants, "<br>")
-- Если нет продуктов, пропускаем эту реакцию
local products = {}
if mainProduct ~= nil then
local productTemplate = "%s [[#chem_%s|%s]]"
-- Заполняем данные для колонки "Вещество"
templateArgs.id = mainProduct.id
for productId, productAmount in pairs(reactPrototype.products) do
templateArgs.name = mainProduct.data.name
templateArgs.color = mainProduct.data.color
templateArgs.textColor = mainProduct.data.textColor
templateArgs.amount = mainProduct.amount
-- Ингредиенты (реагенты)
local productChemData = p.chem[productId]
local reactants = {}
local productText = string.format(productTemplate, productAmount, productChemData.id,  productChemData.name)
local reactantTemplate = "%s [[#chem_%s|%s]]"
table.insert(products, productText)
end
for reactantId, reactantValue in pairs(reactPrototype.reactants) do
-- Эффекты реакции
if tablelength(reactPrototype.effects) then
local reactantChemData = p.chem[reactantId]
for _, effect in pairs(reactPrototype.effects) do
local reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.id,  reactantChemData.name)
if effect.description ~= "" then
if reactantValue.catalyst then
table.insert(products, effect.description)
reactantText = reactantText .. " (катализатор)"
end
table.insert(reactants, reactantText)
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
end
-- Эффекты реакции
if reactPrototype.effects and tablelength(reactPrototype.effects) > 0 then
for _, effect in pairs(reactPrototype.effects) do
if effect.description ~= "" then
table.insert(results, effect.description)
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
Строка 202: Строка 171:
end
end
-- Эффекты реакции
-- Эффекты реакции
if reactPrototype.effects and tablelength(reactPrototype.effects) > 0 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
Строка 229: Строка 198:
local actions = {}
local actions = {}
if reactPrototype.mixingCategories then
for _, mixingCategory in pairs(reactPrototype.mixingCategories) do
for _, mixingCategory in pairs(reactPrototype.mixingCategories) do
local image = getMixingImage(mixingCategory.id)
local image = getMixingImage(mixingCategory.id)
if image ~= nil then
if image ~= nil then
table.insert(actions, string.format("[[File:%s|32px|link=]]", image)) -- Картинка
table.insert(actions, string.format("[[File:%s|32px|link=]]", image)) -- Картинка
end
table.insert(actions, mixingCategory.name or mixingCategory.id) -- Название
end
end
table.insert(actions, mixingCategory.name or mixingCategory.id) -- Название
end
end