Модуль:gases
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
p.gases = mw.text.jsonDecode(mw.title.new(' | p.gases = mw.text.jsonDecode(mw.title.new('User:WikiBotADT/gas_prototypes.json'):getContent()) | ||
p.reactions = mw.text.jsonDecode(mw.title.new('User:WikiBotADT/gasreact_prototypes.json'):getContent()) | |||
local function attachAsNewLine(originalStr, joinStr) | local function attachAsNewLine(originalStr, joinStr) | ||
| Строка 34: | Строка 29: | ||
return effects | return effects | ||
end | end | ||
local function gasLink(gasId) | |||
local gasPrototype = p.gases[gasId] | |||
if gasPrototype == nil then | |||
return gasId | |||
end | |||
return "[[#gas_" .. gasId .. "|" .. gasPrototype.name .. "]]" | |||
end | |||
local function sortedReactions() | |||
local list = {} | |||
for _, reaction in pairs(p.reactions) do | |||
table.insert(list, reaction) | |||
end | |||
table.sort(list, function(a, b) return a.name < b.name end) | |||
return list | |||
end | |||
-- Количество 0 в данных значит, что пропорция зависит от условий и описана в примечании. | |||
local function gasAmounts(gases) | |||
local lines = {} | |||
for gasId, amount in pairs(gases) do | |||
if amount == 0 then | |||
table.insert(lines, gasLink(gasId)) | |||
else | |||
table.insert(lines, tostring(amount) .. " " .. gasLink(gasId)) | |||
end | |||
end | |||
table.sort(lines) | |||
return table.concat(lines, "<br>") | |||
end | |||
local function getConditions(reaction) | |||
local lines = {} | |||
if reaction.minTemp ~= nil and reaction.maxTemp ~= nil then | |||
table.insert(lines, "от " .. reaction.minTemp .. " K до " .. reaction.maxTemp .. " K") | |||
elseif reaction.minTemp ~= nil then | |||
table.insert(lines, "выше " .. reaction.minTemp .. " K") | |||
elseif reaction.maxTemp ~= nil then | |||
table.insert(lines, "ниже " .. reaction.maxTemp .. " K") | |||
end | |||
for gasId, amount in pairs(reaction.requirements) do | |||
table.insert(lines, "не меньше " .. tostring(amount) .. " моль: " .. gasLink(gasId)) | |||
end | |||
return table.concat(lines, "<br>") | |||
end | |||
local function getCatalysts(reaction) | |||
local lines = {} | |||
for _, gasId in ipairs(reaction.catalysts) do | |||
table.insert(lines, gasLink(gasId)) | |||
end | |||
if #lines == 0 then | |||
return "" | |||
end | |||
return "<br>Не расходуется: " .. table.concat(lines, ", ") | |||
end | |||
local function getRecipes(gasId) | |||
local lines = {} | |||
for _, reaction in ipairs(sortedReactions()) do | |||
if reaction.produces[gasId] ~= nil then | |||
table.insert(lines, "[[#gasreact_" .. reaction.id .. "|" .. reaction.name .. "]]") | |||
end | |||
end | |||
return table.concat(lines, "<br>") | |||
end | |||
local fillGasRow | |||
function p.table(frame) | function p.table(frame) | ||
| Строка 44: | Строка 108: | ||
out = out .. '{| class="wikitable sortable" style="width: 100%; text-align: center;"' | out = out .. '{| class="wikitable sortable" style="width: 100%; text-align: center;"' | ||
out = out .. "\n! Газ !! Описание !! Цвет !! Удельная теплоёмкость (Дж/моль·K) !! Показатель адиабаты !! Молярная масса (г/моль) !! Цена за моль !! Эффекты" | out = out .. "\n! Газ !! Описание !! Цвет !! Удельная теплоёмкость (Дж/моль·K) !! Показатель адиабаты !! Молярная масса (г/моль) !! Цена за моль !! Получение !! Эффекты" | ||
local additional = frame.args.additional | local additional = frame.args.additional | ||
| Строка 64: | Строка 128: | ||
end | end | ||
function | fillGasRow = function(gasId) | ||
local gasPrototype = p.gases[gasId] | local gasPrototype = p.gases[gasId] | ||
local out = "" | local out = "" | ||
| Строка 71: | Строка 135: | ||
local textColor = gasPrototype.textColor or "#FFFFFF" | local textColor = gasPrototype.textColor or "#FFFFFF" | ||
out = out .. '\n|- style="background: ' .. color .. '1E; color: ' .. textColor .. '"' | out = out .. '\n|- id="gas_' .. gasId .. '" style="background: ' .. color .. '1E; color: ' .. textColor .. '"' | ||
out = out .. '\n! scope="row" style="font-weight: bold;" | ' .. gasPrototype.name | out = out .. '\n! scope="row" style="font-weight: bold;" | ' .. gasPrototype.name | ||
out = out .. '\n| style="text-align: left;" | ' .. gasPrototype.desc | out = out .. '\n| style="text-align: left;" | ' .. gasPrototype.desc | ||
| Строка 79: | Строка 143: | ||
out = out .. '\n| ' .. tostring(gasPrototype.molarMass or "") | out = out .. '\n| ' .. tostring(gasPrototype.molarMass or "") | ||
out = out .. '\n| ' .. tostring(gasPrototype.pricePerMole or "") | out = out .. '\n| ' .. tostring(gasPrototype.pricePerMole or "") | ||
out = out .. '\n| style="text-align: left;" | ' .. getRecipes(gasId) | |||
out = out .. '\n| style="text-align: left; font-size: 90%;" | ' .. getEffects(gasPrototype) | out = out .. '\n| style="text-align: left; font-size: 90%;" | ' .. getEffects(gasPrototype) | ||
return out | |||
end | |||
function p.reactionTable(frame) | |||
local out = '{| class="wikitable sortable" style="width: 100%;"' | |||
out = out .. "\n! Реакция !! Условия !! Расходуется !! Получается !! Примечания" | |||
for _, reaction in ipairs(sortedReactions()) do | |||
out = out .. '\n|- id="gasreact_' .. reaction.id .. '"' | |||
out = out .. '\n! scope="row" | ' .. reaction.name | |||
out = out .. '\n| ' .. getConditions(reaction) | |||
out = out .. '\n| ' .. gasAmounts(reaction.consumes) .. getCatalysts(reaction) | |||
out = out .. '\n| ' .. gasAmounts(reaction.produces) | |||
out = out .. '\n| ' .. table.concat(reaction.notes, " ") | |||
end | |||
out = out .. "\n|}" | |||
return out | return out | ||
end | end | ||
| Строка 104: | Строка 186: | ||
out = out .. '<table style="width: 100%; border-collapse: collapse; margin: 10px 0;">' | out = out .. '<table style="width: 100%; border-collapse: collapse; margin: 10px 0;">' | ||
out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Физическое описание</td><td style="padding: 4px 8px;">' .. (gasPrototype.physicalDesc or " | out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Физическое описание</td><td style="padding: 4px 8px;">' .. (gasPrototype.physicalDesc or "-") .. '</td></tr>' | ||
out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Цвет</td><td style="padding: 4px 8px;"><span style="background: ' .. color .. '; color: ' .. textColor .. '; padding: 2px 8px; border-radius: 3px;">' .. color .. '</span></td></tr>' | out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Цвет</td><td style="padding: 4px 8px;"><span style="background: ' .. color .. '; color: ' .. textColor .. '; padding: 2px 8px; border-radius: 3px;">' .. color .. '</span></td></tr>' | ||
out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Удельная теплоёмкость</td><td style="padding: 4px 8px;">' .. (gasPrototype.specificHeat and (gasPrototype.specificHeat .. " Дж/моль·K") or " | out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Удельная теплоёмкость</td><td style="padding: 4px 8px;">' .. (gasPrototype.specificHeat and (gasPrototype.specificHeat .. " Дж/моль·K") or "-") .. '</td></tr>' | ||
out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Показатель адиабаты</td><td style="padding: 4px 8px;">' .. tostring(gasPrototype.heatCapacityRatio or " | out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Показатель адиабаты</td><td style="padding: 4px 8px;">' .. tostring(gasPrototype.heatCapacityRatio or "-") .. '</td></tr>' | ||
out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Молярная масса</td><td style="padding: 4px 8px;">' .. (gasPrototype.molarMass and (gasPrototype.molarMass .. " г/моль") or " | out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Молярная масса</td><td style="padding: 4px 8px;">' .. (gasPrototype.molarMass and (gasPrototype.molarMass .. " г/моль") or "-") .. '</td></tr>' | ||
out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Цена за моль</td><td style="padding: 4px 8px;">' .. (gasPrototype.pricePerMole and (gasPrototype.pricePerMole .. " кредитов") or " | out = out .. '<tr style="border-bottom: 1px solid #ddd;"><td style="font-weight: bold; width: 200px; padding: 4px 8px;">Цена за моль</td><td style="padding: 4px 8px;">' .. (gasPrototype.pricePerMole and (gasPrototype.pricePerMole .. " кредитов") or "-") .. '</td></tr>' | ||
out = out .. '</table>' | out = out .. '</table>' | ||