Модуль:tableofchemicals

Вернуться

Строка 9: Строка 9:
for _, reactPrototype in pairs(p.react) do
for _, reactPrototype in pairs(p.react) do
local reactants = {}
local reactants = {}
local reactantTemplate = "%s [[#chem_%s|%s]]"
local reactantTemplate = "<span style='background-color:%s; color:%s; padding:2px 6px; border-radius:3px; display:inline-block;'>%s [[#chem_%s|%s]]</span>"
for reactantId, reactantValue in pairs(reactPrototype.reactants) do
for reactantId, reactantValue in pairs(reactPrototype.reactants) do
local reactantChemData = p.chem[reactantId]
local reactantChemData = p.chem[reactantId]
local reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.id, reactantChemData.name)
local reactantText = string.format(
reactantTemplate,  
reactantChemData.color,
reactantChemData.textColor,
reactantValue.amount,  
reactantChemData.id,  
reactantChemData.name
)
if reactantValue.catalyst then
if reactantValue.catalyst then
reactantText = reactantText .. " (катализатор)"
reactantText = reactantText .. " (катализатор)"
Строка 43: Строка 50:
templateArgs.actions = getActions(reactPrototype)
templateArgs.actions = getActions(reactPrototype)
-- Определяем первое вещество из products для отображения в колонке "Вещество"
local firstProductId = nil
for productId, _ in pairs(reactPrototype.products) do
firstProductId = productId
break
end
if firstProductId and p.chem[firstProductId] then
templateArgs.name = p.chem[firstProductId].name or firstProductId
templateArgs.color = p.chem[firstProductId].color or ""
templateArgs.textColor = p.chem[firstProductId].textColor or ""
else
templateArgs.name = ""
templateArgs.color = ""
templateArgs.textColor = ""
end
local template = "Строка_реакции"
local template = "Строка_реакции"
Строка 165: Строка 155:
local reactPrototype = p.react[reactId]
local reactPrototype = p.react[reactId]
local reactants = {}
local reactants = {}
local reactantTemplate = "%s [[#chem_%s|%s]]"
local reactantTemplate = "<span style='background-color:%s; color:%s; padding:2px 6px; border-radius:3px; display:inline-block;'>%s [[#chem_%s|%s]]</span>"
for reactantId, reactantValue in pairs(reactPrototype.reactants) do
for reactantId, reactantValue in pairs(reactPrototype.reactants) do
local reactantChemData = p.chem[reactantId]
local reactantChemData = p.chem[reactantId]
local reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.id, reactantChemData.name)
local reactantText = string.format(
reactantTemplate,  
reactantChemData.color,
reactantChemData.textColor,
reactantValue.amount,  
reactantChemData.id,  
reactantChemData.name
)
if reactantValue.catalyst then
if reactantValue.catalyst then
reactantText = reactantText .. " (катализатор)"
reactantText = reactantText .. " (катализатор)"
Строка 215: Строка 212:
local actions = {}
local actions = {}
if reactPrototype.mixingCategories and type(reactPrototype.mixingCategories) == "table" 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