Модуль:TableOfChemicals: различия между версиями
мНет описания правки |
мНет описания правки |
||
| Строка 4: | Строка 4: | ||
p.chem = prototypes.chem | p.chem = prototypes.chem | ||
p.react = prototypes.react | p.react = prototypes.react | ||
p.test = function() | |||
mw.log(tablelength(p.chem["Bicaridine"].recipes)) | |||
end | |||
p.fillTable = function(frame) | p.fillTable = function(frame) | ||
local out = "" | local out = "" | ||
| Строка 20: | Строка 25: | ||
templateArgs.recipes_count = tablelength(chemPrototype.recipes) | templateArgs.recipes_count = tablelength(chemPrototype.recipes) | ||
local firstReact = true | |||
if templateArgs.recipes_count == 0 then | |||
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 reactantTemplateWithLink = "%s [[#%s|%s]]" | |||
local reactantTemplate = "%s %s" | |||
for reactantId, reactantValue in pairs(reactPrototype.reactants) do | |||
local reactantChemData = p.chem[reactantId] | |||
local reactantText | |||
if makeALink(group, reactantChemData.id) then | |||
reactantText = string.format(reactantTemplateWithLink, reactantValue.amount, reactantChemData.id, reactantChemData.name) | |||
else | |||
reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.name) | |||
end | |||
table.insert(reactants, reactantText) | |||
end | |||
templateArgs.reactants = table.concat(reactants, "<br>") | |||
local products = {} | |||
for productId, productAmount in pairs(reactPrototype.products) do | |||
local productChemData = p.chem[productId] | |||
local productText = productAmount .. " " .. productChemData.name | |||
table.insert(products, productText) | |||
end | |||
templateArgs.products = table.concat(products, "<br>") | |||
templateArgs.action = "смешать" | |||
local | |||
if | local template = "Строка_химического_вещества" | ||
if firstReact then | |||
template = "Первая_строка_химического_вещества" | |||
firstReact = false | |||
end | end | ||
out = out .. frame:expandTemplate{ title = template, args = templateArgs} | |||
end | end | ||
end | end | ||
end | end | ||