Модуль:TableOfChemicals: различия между версиями
мНет описания правки |
мНет описания правки |
||
| Строка 9: | Строка 9: | ||
local out = "" | local out = "" | ||
local group = frame.args.group | local group = frame.args.group | ||
for _, chemPrototype in pairs(p.chem) do | for _, chemPrototype in pairs(p.chem) do | ||
if group == nil or group == "all" or chemPrototype.group == group then | if group == nil or group == "all" or chemPrototype.group == group then | ||
templateArgs.id = chemPrototype.id | p.fillChemistryRow(chemPrototype.id) | ||
end | |||
end | |||
return out | |||
end | |||
p.fillChemistryRow = function(frame) | |||
return fillChemistryRow(frame.args.id) | |||
end | |||
fillChemistryRow = function(chemPrototypeId) | |||
local chemPrototype = p.chem[chemPrototypeId] -- Считаем что id совпадает с ключем p.chem | |||
local templateArgs = {} | |||
templateArgs.id = chemPrototype.id | |||
templateArgs.name = chemPrototype.name | |||
templateArgs.description = chemPrototype.desc .. " На вид " .. chemPrototype.physicalDesc .. "." | |||
templateArgs.color = getColor(chemPrototype.id) | |||
templateArgs.textColor = getTextColor(chemPrototype.id) | |||
templateArgs.recipes_count = tablelength(chemPrototype.recipes) | |||
templateArgs.reactants = "" | |||
templateArgs.products = "" | |||
templateArgs.action = "" | |||
if templateArgs.recipes_count == 0 then | |||
templateArgs.recipes_count = 1 -- Для заполнения параметра rowspan строки | |||
out = out .. frame:expandTemplate{ title = "Первая_строка_химического_вещества", args = templateArgs} | |||
else | |||
local firstReact = true | |||
for _, reactId in pairs(chemPrototype.recipes) do | |||
local reactPrototype = p.react[reactId] | |||
local reactants = {} | |||
local reactantTemplate = "%s [[#%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) | |||
table.insert(reactants, reactantText) | |||
end | |||
templateArgs.reactants = table.concat(reactants, "<br>") | |||
local products = {} | |||
local productTemplate = "%s [[#%s|%s]]" | |||
templateArgs. | for productId, productAmount in pairs(reactPrototype.products) do | ||
local productChemData = p.chem[productId] | |||
local productText = string.format(productTemplate, productAmount, productChemData.id, productChemData.name) | |||
table.insert(products, productText) | |||
end | |||
templateArgs.products = table.concat(products, "<br>") | |||
templateArgs. | templateArgs.action = "[[File:Beaker.png|32px]]<br>Смешать" | ||
local template = "Строка_химического_вещества" | |||
if firstReact then | |||
template = "Первая_строка_химического_вещества" | |||
firstReact = false | |||
end | end | ||
out = out .. frame:expandTemplate{ title = template, args = templateArgs} | |||
end | end | ||
end | end | ||
end | end | ||
p.fillEffectsTable = function(frame) | p.fillEffectsTable = function(frame) | ||