Модуль:TableOfChemicals: различия между версиями

Нет описания правки
м Серная кислота не существует в раздатчике химикатов. Это миф
Метки: с мобильного устройства из мобильной версии
 
(не показано 19 промежуточных версий 1 участника)
Строка 1: Строка 1:
p = {}
p = {}
p.chem = mw.text.jsonDecode(mw.title.new("User:KrasnoshchekovPavel/chem_prototypes.json"):getContent()) -- Заменить на яна после обновы
p.chem = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/chem_prototypes.json"):getContent())
p.react = mw.text.jsonDecode(mw.title.new("User:KrasnoshchekovPavel/react_prototypes.json"):getContent()) -- Заменить на яна после обновы
p.react = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/react_prototypes.json"):getContent())


p.fillTable = function(frame)
p.fillReactTable = function(frame)
local out = ""
for _, reactPrototype in pairs(p.react) do
if tablelength(reactPrototype.effects) ~= 0 then
local reactants = {}
local reactantTemplate = "%s [[#chem_%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)
if reactantValue.catalyst then
reactantText = reactantText .. " (катализатор)"
end
table.insert(reactants, reactantText)
end
local templateArgs = {}
templateArgs.reactants = table.concat(reactants, "<br>")
local products = {}
local productTemplate = "%s [[#chem_%s|%s]]"
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
-- Эффекты реакции
if tablelength(reactPrototype.effects) then
for _, effect in pairs(reactPrototype.effects) do
if effect.description ~= "" then
table.insert(products, effect.description)
end
end
end
templateArgs.products = table.concat(products, "<br>")
templateArgs.actions = getActions(reactPrototype)
local template = "Строка_реакции"
out = out .. frame:expandTemplate{ title = template, args = templateArgs}
end
end
return out
end
 
p.fillChemTable = function(frame)
local out = ""
local out = ""
Строка 30: Строка 80:
return out
return out
end
end
p.fillContentOfDispencer = function(frame)
local dispencer = frame.args.dispencer
local out = ""
for _, chemId in pairs(dispencersContent()[dispencer]) do
out = out .. frame:expandTemplate{ title = "Кнопка_реагента", args = {chemId, "y"}}
end
return out
end
function dispencersContent()
local content = {
["Химикатов"]={
"Aluminium","Carbon","Chlorine","Copper","Ethanol","Fluorine","Hydrogen","Iodine",
"Iron","Lithium","Mercury","Nitrogen","Oxygen","Phosphorus","Potassium","Radium",
"Silicon","Sodium","Sugar","Sulfur"
},
["Соды"]={
"Water","Ice","Coffee","Cream","Tea","GreenTea","IcedTea","IcedGreenTea",
"Cola","SpaceMountainWind","DrGibb","SpaceUp","TonicWater","SodaWater","LemonLime","Sugar",
"JuiceOrange","JuiceLime","JuiceWatermelon"
},
["Алкоголя"]={
"LemonLime","Sugar","JuiceOrange","JuiceLime","SodaWater","TonicWater","Beer","CoffeeLiqueur",
"Whiskey","Wine","Vodka","Gin","Rum","Tequila","Vermouth","Cognac",
"Ale","Mead"
}
}
return content
end
p.readArg = function(frame)
return mw.text.nowiki(p.chem[frame.args[1]][frame.args[2]])
end


function contains(list, x)
function contains(list, x)
Строка 36: Строка 122:
end
end
return false
return false
end
p.fillChemistryRow = function(frame)
return fillChemistryRow(frame.args.id, frame)
end
end


Строка 76: Строка 156:
local reactantChemData = p.chem[reactantId]
local reactantChemData = p.chem[reactantId]
local reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.id,  reactantChemData.name)
local reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.id,  reactantChemData.name)
if reactantValue.catalyst then
reactantText = reactantText .. " (катализатор)"
end
table.insert(reactants, reactantText)
table.insert(reactants, reactantText)
end
end
Строка 88: Строка 171:
local productText = string.format(productTemplate, productAmount, productChemData.id,  productChemData.name)
local productText = string.format(productTemplate, productAmount, productChemData.id,  productChemData.name)
table.insert(products, productText)
table.insert(products, productText)
end
-- Эффекты реакции
if tablelength(reactPrototype.effects) then
for _, effect in pairs(reactPrototype.effects) do
if effect.description ~= "" then
table.insert(products, effect.description)
end
end
end
end
templateArgs.products = table.concat(products, "<br>")
templateArgs.products = table.concat(products, "<br>")
Строка 129: Строка 220:
local image = getMixingImage(mixingCategory.id)
local image = getMixingImage(mixingCategory.id)
if image ~= nil then
if image ~= nil then
table.insert(actions, string.format("[[File:%s|32px]]", image)) -- Картинка
table.insert(actions, string.format("[[File:%s|32px|link=]]", image)) -- Картинка
end
end
Строка 158: Строка 249:
function getEffects(chemPrototypeId)
function getEffects(chemPrototypeId)
local effectsTable = "{|"
local effects = ""
local chemPrototype = p.chem[chemPrototypeId]
local chemPrototype = p.chem[chemPrototypeId]
if chemPrototype.metabolisms == nil then
if chemPrototype.metabolisms == nil then
return ""
return effects
end
end
for _, metabolismGroup in pairs(chemPrototype.metabolisms) do
for metabolismGroupKey, metabolismGroup in pairs(chemPrototype.metabolisms) do
for _, effect in pairs(metabolismGroup) do
effects = attachAsNewLine(effects, string.format("* %s (%s единиц в секунду)", metabolismGroupKey, metabolismGroup.rate))
for _, effect in pairs(metabolismGroup.effects) do
if effect.description ~= "" then
if effect.description ~= "" then
effectsTable = attachAsNewLine(effectsTable, "|-")
effects = attachAsNewLine(effects, "** "..effect.description)
effectsTable = attachAsNewLine(effectsTable, "|"..effect.description)
end
end
end
end
end
end
effectsTable = attachAsNewLine(effectsTable, "|}")
return effectsTable
return effects
    
    
end
end