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

Модуль:Gases

Материал из Space Station 14 | Время приключений Вики
Версия от 22:53, 4 июня 2026; WikiHampter (обсуждение | вклад)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)

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

local p = {}
p.gases = mw.text.jsonDecode(mw.title.new('Участник:WikiHampter/gas_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)
	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

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%; text-align: center;"'
	out = out .. "\n! Газ !! Описание !! Цвет !! Удельная теплоёмкость (Дж/моль·K) !! Показатель адиабаты !! Молярная масса (г/моль) !! Цена за моль !! Эффекты"

	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

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

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

	out = out .. '\n|- style="background: ' .. color .. '; color: ' .. textColor .. '"'
	out = out .. '\n! scope="row" style="font-weight: bold;" | ' .. gasPrototype.name
	out = out .. '\n| style="text-align: left;" | ' .. gasPrototype.desc
	out = out .. '\n| ' .. 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%;" | ' .. getEffects(gasPrototype)

	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