Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

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

Материал из Space Station 14 | Время приключений Вики
м Добавили альфа-канал к цвету в 50%
мНет описания правки
 
(не показано 5 промежуточных версий 2 участников)
Строка 1: Строка 1:
local p = {}
local p = {}
p.gases = mw.text.jsonDecode(mw.title.new('Участник:WikiHampter/gas_prototypes.json'):getContent())
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 tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end


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 function getProperties(gasPrototype)
return table.concat({
"Теплоёмкость: " .. tostring(gasPrototype.specificHeat) .. " Дж/(моль·K)",
"Адиабата: " .. tostring(gasPrototype.heatCapacityRatio),
"Масса: " .. tostring(gasPrototype.molarMass) .. " г/моль",
"Цена: " .. tostring(gasPrototype.pricePerMole) .. " за моль",
}, "<br>")
end
local function getCollapsedEffects(gasPrototype)
local effects = getEffects(gasPrototype)
if effects == "" then
return ""
end
return '<div class="mw-collapsible mw-collapsed" data-expandtext="Показать" data-collapsetext="Скрыть">Эффекты при вдыхании' .. '<div class="mw-collapsible-content">' .. effects .. '\n</div></div>'
end
local fillGasRow


function p.table(frame)
function p.table(frame)
Строка 43: Строка 124:
end
end


out = out .. '{| class="wikitable sortable" style="width: 100%; text-align: center;"'
out = out .. '{| class="wikitable sortable" style="width: 100%; table-layout: fixed; overflow-wrap: anywhere; font-size: 90%;"'
out = out .. "\n! Газ !! Описание !! Цвет !! Удельная теплоёмкость (Дж/моль·K) !! Показатель адиабаты !! Молярная масса (г/моль) !! Цена за моль !! Эффекты"
out = out .. '\n! style="width: 13%;" | Газ !! style="width: 24%;" | Описание !! style="width: 21%;" | Свойства !! style="width: 17%;" | Получение !! style="width: 25%;" | Эффекты'


local additional = frame.args.additional
local additional = frame.args.additional
Строка 64: Строка 145:
end
end


function fillGasRow(gasId)
fillGasRow = function(gasId)
local gasPrototype = p.gases[gasId]
local gasPrototype = p.gases[gasId]
local out = ""
local out = ""
Строка 71: Строка 152:
local textColor = gasPrototype.textColor or "#FFFFFF"
local textColor = gasPrototype.textColor or "#FFFFFF"


out = out .. '\n|- style="background: ' .. color .. '80; color: ' .. textColor .. '"'
out = out .. '\n|- id="gas_' .. gasId .. '"'
out = out .. '\n! scope="row" style="font-weight: bold;" | ' .. gasPrototype.name
out = out .. '\n! scope="row" style="background: ' .. color .. '; color: ' .. textColor .. ';" | ' .. gasPrototype.name .. '<br><small>' .. gasPrototype.abbreviation .. '</small>'
out = out .. '\n| style="text-align: left;" | ' .. gasPrototype.desc
out = out .. '\n| ' .. gasPrototype.desc
out = out .. '\n| ' .. color
out = out .. '\n| ' .. getProperties(gasPrototype)
out = out .. '\n| ' .. tostring(gasPrototype.specificHeat or "")
out = out .. '\n| ' .. getRecipes(gasId)
out = out .. '\n| ' .. tostring(gasPrototype.heatCapacityRatio or "")
out = out .. '\n| ' .. getCollapsedEffects(gasPrototype)
out = out .. '\n| ' .. tostring(gasPrototype.molarMass or "")
out = out .. '\n| ' .. tostring(gasPrototype.pricePerMole or "")
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%; table-layout: fixed; overflow-wrap: anywhere; font-size: 90%;"'
out = out .. '\n! style="width: 15%;" | Реакция !! style="width: 20%;" | Условия !! style="width: 18%;" | Расходуется !! style="width: 17%;" | Получается !! style="width: 30%;" | Примечания'
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: Строка 199:


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 "—") .. '</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.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 "—") .. '</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;">' .. 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.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 .. '<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>'



Текущая версия от 11:51, 30 октября 2026

Для документации этого модуля может быть создана страница Модуль:Gases/doc

local p = {}
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)
	return originalStr .. "\n" .. joinStr
end

local function contains(list, x)
	for _, v in ipairs(list) do
		if v == x then return true end
	end
	return false
end

local function getEffects(gasPrototype)
	local effects = ""
	if gasPrototype.metabolisms == nil then
		return effects
	end
	for metabolismGroupKey, metabolismGroup in pairs(gasPrototype.metabolisms) do
		effects = attachAsNewLine(effects, "* " .. metabolismGroupKey .. " (" .. tostring(metabolismGroup.rate) .. " единиц в секунду)")
		for _, effect in ipairs(metabolismGroup.effects) do
			if effect.description ~= "" then
				effects = attachAsNewLine(effects, "** " .. effect.description)
			end
		end
	end
	return effects
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 function getProperties(gasPrototype)
	return table.concat({
		"Теплоёмкость: " .. tostring(gasPrototype.specificHeat) .. " Дж/(моль·K)",
		"Адиабата: " .. tostring(gasPrototype.heatCapacityRatio),
		"Масса: " .. tostring(gasPrototype.molarMass) .. " г/моль",
		"Цена: " .. tostring(gasPrototype.pricePerMole) .. " за моль",
	}, "<br>")
end

local function getCollapsedEffects(gasPrototype)
	local effects = getEffects(gasPrototype)
	if effects == "" then
		return ""
	end
	return '<div class="mw-collapsible mw-collapsed" data-expandtext="Показать" data-collapsetext="Скрыть">Эффекты при вдыхании' .. '<div class="mw-collapsible-content">' .. effects .. '\n</div></div>'
end

local fillGasRow

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

	out = out .. '{| class="wikitable sortable" style="width: 100%; table-layout: fixed; overflow-wrap: anywhere; font-size: 90%;"'
	out = out .. '\n! style="width: 13%;" | Газ !! style="width: 24%;" | Описание !! style="width: 21%;" | Свойства !! style="width: 17%;" | Получение !! style="width: 25%;" | Эффекты'

	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)
		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)
		end
	end

	out = out .. "\n|}"
	return out
end

fillGasRow = function(gasId)
	local gasPrototype = p.gases[gasId]
	local out = ""

	local color = gasPrototype.color or "#000000"
	local textColor = gasPrototype.textColor or "#FFFFFF"

	out = out .. '\n|- id="gas_' .. gasId .. '"'
	out = out .. '\n! scope="row" style="background: ' .. color .. '; color: ' .. textColor .. ';" | ' .. gasPrototype.name .. '<br><small>' .. gasPrototype.abbreviation .. '</small>'
	out = out .. '\n| ' .. gasPrototype.desc
	out = out .. '\n| ' .. getProperties(gasPrototype)
	out = out .. '\n| ' .. getRecipes(gasId)
	out = out .. '\n| ' .. getCollapsedEffects(gasPrototype)

	return out
end

function p.reactionTable(frame)
	local out = '{| class="wikitable sortable" style="width: 100%; table-layout: fixed; overflow-wrap: anywhere; font-size: 90%;"'
	out = out .. '\n! style="width: 15%;" | Реакция !! style="width: 20%;" | Условия !! style="width: 18%;" | Расходуется !! style="width: 17%;" | Получается !! style="width: 30%;" | Примечания'

	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
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>'

	out = out .. getEffects(gasPrototype)

	out = out .. "</div>"
	return out
end

return p