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

Материал из Space Stories Wiki
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}


function p.recipe(frame)
local borderColors = {
gas = "#adff2f",
liquid = "#1e88e5",
solid = "#ff9800"
}
 
function p.render(frame)
local args = frame:getParent().args
local args = frame:getParent().args
local name = args.name or 'Неизвестно'
local type = args.type or "gas"
local color = args.color or '#cccccc'
local name = args.name or "Название"
local product = args.product or ''
local description = args.description or "Краткое описание"
local description = args.description or ''
local recipes = mw.text.split(args.recipes or "", "\n")
local effect = args.effect or ''
local effects = mw.text.split(args.effects or "", "\n")
local recipe = args.recipe or ''
 
local container = mw.html.create("div")
:addClass("recipe-block")
:addClass(type)
:css("border-left", "4px solid " .. (borderColors[type] or "#999"))
 
container:tag("div")
:addClass("recipe-name")
:wikitext(name)
 
-- Рецепты
local recipeSection = container:tag("div"):addClass("recipe-section")
recipeSection:tag("div")
:addClass("section-title")
:attr("onclick", "toggleSection(this)")
:wikitext("Рецепты")
local recipeContent = recipeSection:tag("div"):addClass("section-content")
for _, line in ipairs(recipes) do
if line ~= "" then
local parts = mw.text.split(line, "=>")
local output = mw.text.trim(parts[1] or "?")
local inputs = mw.text.trim(parts[2] or "?")
local recipeItem = recipeContent:tag("div"):addClass("recipe-item")
recipeItem:tag("div"):addClass("output"):wikitext(output)
recipeItem:tag("div"):addClass("ingredients"):wikitext("Смешайте:<br>" .. inputs)
end
end
 
-- Эффекты
local effectSection = container:tag("div"):addClass("effect-section")
effectSection:tag("div")
:addClass("section-title")
:attr("onclick", "toggleSection(this)")
:wikitext("Эффекты")


local function collapse(title, content)
local effectContent = effectSection:tag("div"):addClass("section-content")
return string.format(
for _, effect in ipairs(effects) do
'<div class="alchemy-collapse">' ..
if effect ~= "" then
'<div class="alchemy-toggle" onclick="this.classList.toggle(\'open\')">%s</div>' ..
effectContent:tag("div"):addClass("effect"):wikitext(effect)
'<div class="alchemy-content">%s</div>' ..
end
'</div>',
title, content
)
end
end


local recipeBlock = collapse('Рецепт', recipe)
-- Описание
local effectBlock = collapse('Эффекты', effect)
container:tag("div"):addClass("description"):wikitext(description)


return string.format([[
return tostring(container)
<div class="alchemy-block" style="border-color:%s">
<div class="alchemy-header" style="background:%s">%s</div>
<div class="alchemy-body">
<div class="alchemy-product">%s</div>
%s
%s
<div class="alchemy-description">%s</div>
</div>
</div>
]], color, color, name, product, recipeBlock, effectBlock, description)
end
end


return p
return p

Версия от 02:54, 17 июня 2025

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

local p = {}

local borderColors = {
	gas = "#adff2f",
	liquid = "#1e88e5",
	solid = "#ff9800"
}

function p.render(frame)
	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")
		:addClass("recipe-block")
		:addClass(type)
		:css("border-left", "4px solid " .. (borderColors[type] or "#999"))

	container:tag("div")
		:addClass("recipe-name")
		:wikitext(name)

	-- Рецепты
	local recipeSection = container:tag("div"):addClass("recipe-section")
	recipeSection:tag("div")
		:addClass("section-title")
		:attr("onclick", "toggleSection(this)")
		:wikitext("Рецепты")
	
	local recipeContent = recipeSection:tag("div"):addClass("section-content")
	for _, line in ipairs(recipes) do
		if line ~= "" then
			local parts = mw.text.split(line, "=>")
			local output = mw.text.trim(parts[1] or "?")
			local inputs = mw.text.trim(parts[2] or "?")
			local recipeItem = recipeContent:tag("div"):addClass("recipe-item")
			recipeItem:tag("div"):addClass("output"):wikitext(output)
			recipeItem:tag("div"):addClass("ingredients"):wikitext("Смешайте:<br>" .. inputs)
		end
	end

	-- Эффекты
	local effectSection = container:tag("div"):addClass("effect-section")
	effectSection:tag("div")
		:addClass("section-title")
		:attr("onclick", "toggleSection(this)")
		: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

	-- Описание
	container:tag("div"):addClass("description"):wikitext(description)

	return tostring(container)
end

return p