Модуль:TableOfChemicals
Материал из Space Station 14 Вики
Для документации этого модуля может быть создана страница Модуль: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) 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(products, "<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) local out = "{|" -- Объявление таблицы (Условие | Эффект) local effects = frame.args.effects local rowTemplate = "|-\n| %s || %s" for _, effect in pairs(effects) do out = attachAsNewLine(out, string.format(rowTemplate, effect.condition, effect.effect)) end out = attachAsNewLine(out, "|}") -- Конец таблицы local a = 0 a = 1/a return out end function getEffects(chemPrototype) local effects = {} local effect = {} effect.condition = "Быть в баньке" effect.effect = "+9 к хилке" table.insert(effects, effect) local effect = {} effect.condition = "Счастье" effect.effect = "+99 к недпоониманию окружающих" table.insert(effects, effect) return effects end function tablelength(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end function attachAsNewLine(originalStr, joinStr) return originalStr .. "\n" .. joinStr end return p