Модуль:TableOfChemicals: различия между версиями
Материал из Space Station 14 Вики
мНет описания правки |
мНет описания правки |
||
Строка 10: | Строка 10: | ||
local out = "" | local out = "" | ||
local group = frame.args.group | local group = frame.args.group | ||
local templateArgs = {} | local templateArgs = {} | ||
for _, chemPrototype in pairs(p.chem) do | for _, chemPrototype in pairs(p.chem) do | ||
if group == nil or chemPrototype.group == group then | if group == nil or chemPrototype.group == group then | ||
templateArgs.name = chemPrototype.name | templateArgs.name = chemPrototype.name | ||
templateArgs.description = chemPrototype.desc .. " На вид " .. chemPrototype.physicalDesc .. "." | templateArgs.description = chemPrototype.desc .. " На вид " .. chemPrototype.physicalDesc .. "." | ||
Строка 27: | Строка 22: | ||
local firstReact = true | local firstReact = true | ||
for _, reactId in pairs(chemPrototype.recipes) do | for _, reactId in pairs(chemPrototype.recipes) do | ||
local reactPrototype = p.react[reactId] | local reactPrototype = p.react[reactId] | ||
local reactants = {} | local reactants = {} | ||
for reactantId, reactantValue in pairs(reactPrototype.reactants) do | for reactantId, reactantValue in pairs(reactPrototype.reactants) do | ||
Строка 68: | Строка 61: | ||
p.fillEffectsTable = function(frame) | p.fillEffectsTable = function(frame) | ||
return "effects" | return "effects" | ||
end | end | ||
Строка 84: | Строка 71: | ||
function getEffects(id) | function getEffects(id) | ||
return "" | return "нету ничего" | ||
end | end | ||
return p | return p |
Версия от 21:25, 23 апреля 2024
Для документации этого модуля может быть создана страница Модуль:TableOfChemicals/doc
p = {} local prototypes = mw.loadData("Module:Chemistry Lookup/data") p.chem = prototypes.chem p.react = prototypes.react p.fillTable = function(frame) local out = {} local out = "" local group = frame.args.group local templateArgs = {} for _, chemPrototype in pairs(p.chem) do if group == nil or chemPrototype.group == group then templateArgs.name = chemPrototype.name templateArgs.description = chemPrototype.desc .. " На вид " .. chemPrototype.physicalDesc .. "." templateArgs.effects = getEffects(chemPrototype.id) templateArgs.recipes_count = tablelength(chemPrototype.recipes) local firstReact = true for _, reactId in pairs(chemPrototype.recipes) do local reactPrototype = p.react[reactId] local reactants = {} for reactantId, reactantValue in pairs(reactPrototype.reactants) do local reactantChemData = p.chem[reactantId] local reactantText = reactantValue.amount .. " " .. reactantChemData.name 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(reactants, "<br>") templateArgs.action = "смешать" local template = "Строка_химического_вещества" if firstReact then template = "Первая_строка_химического_вещества" firstReact = false end out = out .. frame:expandTemplate{ title = template, args = templateArgs} end end end return out end p.fillEffectsTable = function(frame) return "effects" end function tablelength(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end function getEffects(id) return "нету ничего" end return p