Модуль: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]]"
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(
'<span style="background-color:%s; color:%s; padding:2px 5px; border-radius:3px; display:inline-block; margin:1px;">%s</span> <span style="background-color:%s; color:%s; padding:2px 5px; border-radius:3px; display:inline-block; margin:1px;">[[#chem_%s|%s]]</span>',
reactantChemData.color or "#808080",
reactantChemData.textColor or "#FFFFFF",
reactantValue.amount,
reactantChemData.color or "#808080",
reactantChemData.textColor or "#FFFFFF",
reactantChemData.id,
reactantChemData.name
)
if reactantValue.catalyst then
if reactantValue.catalyst then
reactantText = reactantText .. " (катализатор)"
reactantText = reactantText .. " (катализатор)"
Строка 33: Строка 24:
local products = {}
local products = {}
local productTemplate = "%s [[#chem_%s|%s]]"
for productId, productAmount in pairs(reactPrototype.products) do
for productId, productAmount in pairs(reactPrototype.products) do
local productChemData = p.chem[productId]
local productChemData = p.chem[productId]
-- Создаем ссылку с цветом на названии
local productText = string.format(productTemplate, productAmount, productChemData.id, productChemData.name)
local productText = string.format(
'<span style="background-color:%s; color:%s; padding:2px 5px; border-radius:3px; display:inline-block; margin:1px;">%s</span> <span style="background-color:%s; color:%s; padding:2px 5px; border-radius:3px; display:inline-block; margin:1px;">[[#chem_%s|%s]]</span>',
productChemData.color or "#808080",
productChemData.textColor or "#FFFFFF",
productAmount,
productChemData.color or "#808080",
productChemData.textColor or "#FFFFFF",
productChemData.id,
productChemData.name
)
table.insert(products, productText)
table.insert(products, productText)
end
end