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

Материал из Space Stories Wiki
Нет описания правки
Нет описания правки
Строка 20: Строка 20:


local html = {}
local html = {}
table.insert(html, '<div style="border: 2px solid ' .. borderColor .. '; padding: 1em; border-radius: 8px; background: ' .. backgroundColor .. '; max-width: 400px; text-align: center;">')
table.insert(html, '<div style="border: 2px solid ' .. borderColor .. '; padding: 1em; border-radius: 8px; background: ' .. backgroundColor .. '; max-width: 600px;">')
table.insert(html, '<h3 style="margin-top:0;">' .. title .. '</h3>')
table.insert(html, '<h3 style="margin-top:0; text-align:center;">' .. title .. '</h3>')


-- Ингредиенты вертикально
-- Flex-блок с тремя колонками
table.insert(html, listBlock(ingredients))
table.insert(html, '<div style="display: flex; justify-content: space-between; text-align: center;">')


-- Смешать
-- Ингредиенты слева
table.insert(html, '<div style="font-weight:bold; margin: 0.5em 0;">СМЕШАТЬ</div>')
table.insert(html, '<div style="flex: 1;">' .. listBlock(ingredients) .. '</div>')


-- Результат
-- Смешать по центру
table.insert(html, '<div style="font-weight:bold;">' .. result .. '</div>')
table.insert(html, '<div style="flex: 0 0 100px; display: flex; align-items: center; justify-content: center; font-weight:bold;">СМЕШАТЬ</div>')


-- Эффекты
-- Результат справа
table.insert(html, '<div style="flex: 1;">' .. listBlock(result) .. '</div>')
 
table.insert(html, '</div>')
 
-- Эффекты (опционально)
if effects ~= "" then
if effects ~= "" then
table.insert(html, '<hr><b>Эффекты:</b><ul>')
table.insert(html, '<hr><b>Эффекты:</b><ul>')

Версия от 10:50, 16 мая 2025

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

local p = {}

function p.card(frame)
	local args = frame:getParent().args
	local title = args["Название"] or "Без названия"
	local ingredients = args["Ингредиенты"] or ""
	local result = args["Результат"] or ""
	local effects = args["Эффекты"] or ""

	local borderColor = args["ЦветРамки"] or "#ccc"
	local backgroundColor = args["ЦветФона"] or "#f9f9f9"

	local function listBlock(text)
		local items = {}
		for item in mw.text.gsplit(text, ";") do
			table.insert(items, "<div>" .. mw.text.trim(item) .. "</div>")
		end
		return table.concat(items, "\n")
	end

	local html = {}
	table.insert(html, '<div style="border: 2px solid ' .. borderColor .. '; padding: 1em; border-radius: 8px; background: ' .. backgroundColor .. '; max-width: 600px;">')
	table.insert(html, '<h3 style="margin-top:0; text-align:center;">' .. title .. '</h3>')

	-- Flex-блок с тремя колонками
	table.insert(html, '<div style="display: flex; justify-content: space-between; text-align: center;">')

	-- Ингредиенты слева
	table.insert(html, '<div style="flex: 1;">' .. listBlock(ingredients) .. '</div>')

	-- Смешать по центру
	table.insert(html, '<div style="flex: 0 0 100px; display: flex; align-items: center; justify-content: center; font-weight:bold;">СМЕШАТЬ</div>')

	-- Результат справа
	table.insert(html, '<div style="flex: 1;">' .. listBlock(result) .. '</div>')

	table.insert(html, '</div>')

	-- Эффекты (опционально)
	if effects ~= "" then
		table.insert(html, '<hr><b>Эффекты:</b><ul>')
		for item in mw.text.gsplit(effects, ";") do
			table.insert(html, "<li>" .. mw.text.trim(item) .. "</li>")
		end
		table.insert(html, "</ul>")
	end

	table.insert(html, "</div>")
	return table.concat(html, "\n")
end

return p