Модуль:Gases: различия между версиями
Материал из Space Station 14 | Время приключений Вики
Дополнительные действия
м Замена пользователя на себя |
мНет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
p.gases = mw.text.jsonDecode(mw.title.new('Участник:WikiHampter/gas_prototypes.json'):getContent()) | |||
function p.table(frame) | function p.table(frame) | ||
local out = "" | |||
local group = frame.args.group | |||
local groups | |||
if group ~= nil and group ~= "" then | |||
groups = mw.text.split(group, ",") | |||
end | |||
local additional = frame.args.additional | |||
if additional ~= nil and additional ~= "" then | |||
local additionalGasIds = mw.text.split(additional, ",") | |||
for _, gasId in ipairs(additionalGasIds) do | |||
out = out .. fillGasRow(gasId, frame) | |||
end | |||
end | |||
for _, gasPrototype in pairs(p.gases) do | |||
if group == nil or group == "" or contains(groups, gasPrototype.group) then | |||
out = out .. fillGasRow(gasPrototype.id, frame) | |||
end | |||
end | |||
return out | |||
end | |||
function fillGasRow(gasId, frame) | |||
local gasPrototype = p.gases[gasId] | |||
local out = "" | |||
local color = gasPrototype.color or "#000000" | |||
local textColor = gasPrototype.textColor or "#FFFFFF" | |||
out = out .. '|- style="background: ' .. color .. '; color: ' .. textColor .. '"' | |||
out = out .. '\n| ' .. gasPrototype.name | |||
out = out .. '\n| style="text-align: left;" | ' .. gasPrototype.desc | |||
out = out .. '\n| style="text-align: center;" | ' .. color | |||
out = out .. '\n| ' .. tostring(gasPrototype.specificHeat or "") | |||
out = out .. '\n| ' .. tostring(gasPrototype.heatCapacityRatio or "") | |||
out = out .. '\n| ' .. tostring(gasPrototype.molarMass or "") | |||
out = out .. '\n| ' .. tostring(gasPrototype.pricePerMole or "") | |||
out = out .. '\n| style="text-align: left; font-size: 90%;" | ' | |||
if gasPrototype.metabolisms ~= nil then | |||
local first = true | |||
for metabolismGroupKey, metabolismGroup in pairs(gasPrototype.metabolisms) do | |||
if not first then | |||
out = out .. "\n'''" | |||
end | |||
first = false | |||
out = out .. "'''" .. metabolismGroupKey .. " (" .. tostring(metabolismGroup.rate) .. " ед/сек)'''" | |||
for _, effect in ipairs(metabolismGroup.effects) do | |||
if effect.description ~= "" then | |||
out = out .. "\n* " .. effect.description | |||
end | |||
end | |||
end | |||
else | |||
out = out .. "—" | |||
end | |||
out = out .. "\n" | |||
return out | |||
end | end | ||
function p.single(frame) | function p.single(frame) | ||
local gasId = frame.args[1] or frame.args.id or "" | |||
if gasId == "" then | |||
return '<div class="error">Не указан ID газа. Использование: {{#invoke:Gases|single|id=Oxygen}}</div>' | |||
end | |||
local gasPrototype = p.gases[gasId] | |||
if not gasPrototype then | |||
return '<div class="error">Газ с ID "' .. mw.text.encode(gasId) .. '" не найден</div>' | |||
end | |||
local color = gasPrototype.color or "#000000" | |||
local textColor = gasPrototype.textColor or "#FFFFFF" | |||
local out = "" | |||
out = out .. '<div style="border: 2px solid ' .. color .. '; border-radius: 8px; padding: 10px; margin: 10px 0; background: #f8f9fa;">' | |||
out = out .. '<div style="font-size: 1.5em; font-weight: bold; color: ' .. color .. ';">' .. gasPrototype.name .. '</div>' | |||
out = out .. '<div style="margin: 5px 0; font-style: italic;">' .. gasPrototype.desc .. '</div>' | |||
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 "—") .. '</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 "—") .. '</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 "—") .. '</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 "—") .. '</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 "—") .. '</td></tr>' | |||
out = out .. '</table>' | |||
if gasPrototype.metabolisms ~= nil then | |||
out = out .. "<h3>Эффекты метаболизма</h3>" | |||
for metabolismGroupKey, metabolismGroup in pairs(gasPrototype.metabolisms) do | |||
out = out .. "<h4>" .. metabolismGroupKey .. " (" .. tostring(metabolismGroup.rate) .. " ед/сек)</h4>" | |||
out = out .. "<ul>" | |||
for _, effect in ipairs(metabolismGroup.effects) do | |||
if effect.description ~= "" then | |||
out = out .. "<li>" .. effect.description .. "</li>" | |||
end | |||
end | |||
out = out .. "</ul>" | |||
end | |||
end | |||
out = out .. "</div>" | |||
return out | |||
end | |||
function contains(list, x) | |||
for _, v in ipairs(list) do | |||
if v == x then return true end | |||
end | |||
return false | |||
end | end | ||
return p | return p | ||
Версия от 22:52, 4 июня 2026
Для документации этого модуля может быть создана страница Модуль:Gases/doc
local p = {}
p.gases = mw.text.jsonDecode(mw.title.new('Участник:WikiHampter/gas_prototypes.json'):getContent())
function p.table(frame)
local out = ""
local group = frame.args.group
local groups
if group ~= nil and group ~= "" then
groups = mw.text.split(group, ",")
end
local additional = frame.args.additional
if additional ~= nil and additional ~= "" then
local additionalGasIds = mw.text.split(additional, ",")
for _, gasId in ipairs(additionalGasIds) do
out = out .. fillGasRow(gasId, frame)
end
end
for _, gasPrototype in pairs(p.gases) do
if group == nil or group == "" or contains(groups, gasPrototype.group) then
out = out .. fillGasRow(gasPrototype.id, frame)
end
end
return out
end
function fillGasRow(gasId, frame)
local gasPrototype = p.gases[gasId]
local out = ""
local color = gasPrototype.color or "#000000"
local textColor = gasPrototype.textColor or "#FFFFFF"
out = out .. '|- style="background: ' .. color .. '; color: ' .. textColor .. '"'
out = out .. '\n| ' .. gasPrototype.name
out = out .. '\n| style="text-align: left;" | ' .. gasPrototype.desc
out = out .. '\n| style="text-align: center;" | ' .. color
out = out .. '\n| ' .. tostring(gasPrototype.specificHeat or "")
out = out .. '\n| ' .. tostring(gasPrototype.heatCapacityRatio or "")
out = out .. '\n| ' .. tostring(gasPrototype.molarMass or "")
out = out .. '\n| ' .. tostring(gasPrototype.pricePerMole or "")
out = out .. '\n| style="text-align: left; font-size: 90%;" | '
if gasPrototype.metabolisms ~= nil then
local first = true
for metabolismGroupKey, metabolismGroup in pairs(gasPrototype.metabolisms) do
if not first then
out = out .. "\n'''"
end
first = false
out = out .. "'''" .. metabolismGroupKey .. " (" .. tostring(metabolismGroup.rate) .. " ед/сек)'''"
for _, effect in ipairs(metabolismGroup.effects) do
if effect.description ~= "" then
out = out .. "\n* " .. effect.description
end
end
end
else
out = out .. "—"
end
out = out .. "\n"
return out
end
function p.single(frame)
local gasId = frame.args[1] or frame.args.id or ""
if gasId == "" then
return '<div class="error">Не указан ID газа. Использование: {{#invoke:Gases|single|id=Oxygen}}</div>'
end
local gasPrototype = p.gases[gasId]
if not gasPrototype then
return '<div class="error">Газ с ID "' .. mw.text.encode(gasId) .. '" не найден</div>'
end
local color = gasPrototype.color or "#000000"
local textColor = gasPrototype.textColor or "#FFFFFF"
local out = ""
out = out .. '<div style="border: 2px solid ' .. color .. '; border-radius: 8px; padding: 10px; margin: 10px 0; background: #f8f9fa;">'
out = out .. '<div style="font-size: 1.5em; font-weight: bold; color: ' .. color .. ';">' .. gasPrototype.name .. '</div>'
out = out .. '<div style="margin: 5px 0; font-style: italic;">' .. gasPrototype.desc .. '</div>'
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 "—") .. '</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 "—") .. '</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 "—") .. '</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 "—") .. '</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 "—") .. '</td></tr>'
out = out .. '</table>'
if gasPrototype.metabolisms ~= nil then
out = out .. "<h3>Эффекты метаболизма</h3>"
for metabolismGroupKey, metabolismGroup in pairs(gasPrototype.metabolisms) do
out = out .. "<h4>" .. metabolismGroupKey .. " (" .. tostring(metabolismGroup.rate) .. " ед/сек)</h4>"
out = out .. "<ul>"
for _, effect in ipairs(metabolismGroup.effects) do
if effect.description ~= "" then
out = out .. "<li>" .. effect.description .. "</li>"
end
end
out = out .. "</ul>"
end
end
out = out .. "</div>"
return out
end
function contains(list, x)
for _, v in ipairs(list) do
if v == x then return true end
end
return false
end
return p