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

Материал из Space Stories Wiki
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}
local borderColors = {
gas = "#adff2f",
liquid = "#1e88e5",
solid = "#ff9800"
}


function p.render(frame)
function p.render(frame)
local args = frame:getParent().args
local args = frame:getParent().args
local type = args.type or "gas"
local name = args.name or "Название"
local description = args.description or "Краткое описание"
local recipes = mw.text.split(args.recipes or "", "\n")
local effects = mw.text.split(args.effects or "", "\n")


local container = mw.html.create("div")
local title = args['название'] or 'Без названия'
:addClass("recipe-block")
local recipe = {}
:addClass(type)
local i = 1
:css("border-left", "4px solid " .. (borderColors[type] or "#999"))


container:tag("div")
while args['ингредиент' .. i] do
:addClass("recipe-name")
table.insert(recipe, args['ингредиент' .. i])
:wikitext(name)
i = i + 1
end


-- Рецепты
local result = args['результат'] or 'Неизвестно'
local recipeSection = container:tag("div"):addClass("recipe-section")
local effects = {}
recipeSection:tag("div")
i = 1
:addClass("section-title")
 
:attr("onclick", "toggleSection(this)")
while args['эффект' .. i] do
:wikitext("Рецепты")
table.insert(effects, args['эффект' .. i])
i = i + 1
local recipeContent = recipeSection:tag("div"):addClass("section-content")
end
for _, line in ipairs(recipes) do
 
if line ~= "" then
local description = args['описание'] or 'Нет описания.'
local parts = mw.text.split(line, "=>")
 
local output = mw.text.trim(parts[1] or "?")
local out = {}
local inputs = mw.text.trim(parts[2] or "?")
table.insert(out, '<div class="alchemy-recipe-card" style="border:1px solid #555;padding:1em;margin:1em 0;background:#1a1a1a;color:#eee;border-radius:12px;">')
local recipeItem = recipeContent:tag("div"):addClass("recipe-item")
table.insert(out, '<div style="font-size:1.5em;font-weight:bold;margin-bottom:0.5em;">' .. title .. '</div>')
recipeItem:tag("div"):addClass("output"):wikitext(output)
 
recipeItem:tag("div"):addClass("ingredients"):wikitext("Смешайте:<br>" .. inputs)
-- Рецепт
end
table.insert(out, '<div style="margin-bottom:0.5em;"><b>Рецепт</b><ul>')
for _, r in ipairs(recipe) do
table.insert(out, '<li>' .. r .. '</li>')
end
end
table.insert(out, '<li><i>Смешайте</i></li>')
table.insert(out, '<li><b>' .. result .. '</b></li>')
table.insert(out, '</ul></div>')


-- Эффекты
-- Эффекты
local effectSection = container:tag("div"):addClass("effect-section")
if #effects > 0 then
effectSection:tag("div")
table.insert(out, '<div style="margin-bottom:0.5em;"><b>Эффекты</b><ul>')
:addClass("section-title")
for _, e in ipairs(effects) do
:attr("onclick", "toggleSection(this)")
table.insert(out, '<li>' .. e .. '</li>')
:wikitext("Эффекты")
 
local effectContent = effectSection:tag("div"):addClass("section-content")
for _, effect in ipairs(effects) do
if effect ~= "" then
effectContent:tag("div"):addClass("effect"):wikitext(effect)
end
end
table.insert(out, '</ul></div>')
end
end


-- Описание
-- Описание
container:tag("div"):addClass("description"):wikitext(description)
table.insert(out, '<div><b>Описание</b><br>' .. description .. '</div>')
table.insert(out, '</div>')


return tostring(container)
return table.concat(out, '\n')
end
end


return p
return p

Версия от 17:12, 20 июня 2025

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

local p = {}

function p.render(frame)
	local args = frame:getParent().args

	local title = args['название'] or 'Без названия'
	local recipe = {}
	local i = 1

	while args['ингредиент' .. i] do
		table.insert(recipe, args['ингредиент' .. i])
		i = i + 1
	end

	local result = args['результат'] or 'Неизвестно'
	local effects = {}
	i = 1

	while args['эффект' .. i] do
		table.insert(effects, args['эффект' .. i])
		i = i + 1
	end

	local description = args['описание'] or 'Нет описания.'

	local out = {}
	table.insert(out, '<div class="alchemy-recipe-card" style="border:1px solid #555;padding:1em;margin:1em 0;background:#1a1a1a;color:#eee;border-radius:12px;">')
	table.insert(out, '<div style="font-size:1.5em;font-weight:bold;margin-bottom:0.5em;">' .. title .. '</div>')

	-- Рецепт
	table.insert(out, '<div style="margin-bottom:0.5em;"><b>Рецепт</b><ul>')
	for _, r in ipairs(recipe) do
		table.insert(out, '<li>' .. r .. '</li>')
	end
	table.insert(out, '<li><i>Смешайте</i></li>')
	table.insert(out, '<li><b>' .. result .. '</b></li>')
	table.insert(out, '</ul></div>')

	-- Эффекты
	if #effects > 0 then
		table.insert(out, '<div style="margin-bottom:0.5em;"><b>Эффекты</b><ul>')
		for _, e in ipairs(effects) do
			table.insert(out, '<li>' .. e .. '</li>')
		end
		table.insert(out, '</ul></div>')
	end

	-- Описание
	table.insert(out, '<div><b>Описание</b><br>' .. description .. '</div>')
	table.insert(out, '</div>')

	return table.concat(out, '\n')
end

return p