Модуль:TableOfChemicals: различия между версиями
Материал из Space Station 14 Вики
мНет описания правки |
мНет описания правки |
||
Строка 1: | Строка 1: | ||
local prototypes = mw.loadData("Module:Chemistry Lookup/data") | |||
p = {} | p = {} | ||
p.fillTable = function(frame) | p.fillTable = function(frame) | ||
local out = {} | local out = {} | ||
for | local group = frame.args.group | ||
local out = "" | |||
local group = frame.args.group | |||
--local chemPrototype | |||
--local reactPrototype | |||
local templateArgs = {} | |||
for _, chemPrototype in pairs(p.chem) do | |||
--chemPrototype = p.chem[chemPrototypeKey] | |||
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) | |||
for _, reactId in pairs(chemPrototype.recipes) do | |||
--reactPrototype = p.react[reactPrototypeKey] | |||
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 = "смешать" | |||
out = out .. frame:expandTemplate{ title = "Первая_строка_химического_вещества", args = templateArgs} | |||
end | |||
end | |||
end | end | ||
return | return out | ||
end | end | ||
Строка 19: | Строка 69: | ||
return "effects" | 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 | end | ||
return p | return p |
Версия от 21:13, 23 апреля 2024
Для документации этого модуля может быть создана страница Модуль:TableOfChemicals/doc
local prototypes = mw.loadData("Module:Chemistry Lookup/data") p = {} p.fillTable = function(frame) local out = {} local group = frame.args.group local out = "" local group = frame.args.group --local chemPrototype --local reactPrototype local templateArgs = {} for _, chemPrototype in pairs(p.chem) do --chemPrototype = p.chem[chemPrototypeKey] 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) for _, reactId in pairs(chemPrototype.recipes) do --reactPrototype = p.react[reactPrototypeKey] 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 = "смешать" out = out .. frame:expandTemplate{ title = "Первая_строка_химического_вещества", args = templateArgs} end end end return out end p.fillEffectsTable = function(frame) local out = {} for idx = 1, 5 do table.insert(out, idx) end 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