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

Материал из Space Stories Wiki
Нет описания правки
Нет описания правки
 
(не показано 9 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}


local darkColors = {
function p.recipe(frame)
    border = "#338833",
local args = frame:getParent().args
    bg = "#1a2a1a",
local name = args.name or 'Неизвестно'
    border2 = "#cc7744",
local color = args.color or '#cccccc'
    bg2 = "#2a1a12",
local product = args.product or ''
    border3 = "#2277cc",
local description = args.description or ''
    bg3 = "#121a26"
local effect = args.effect or ''
}
local recipe = args.recipe or ''


local function renderIngredients(ingredients)
local function collapse(title, content)
    local parts = {}
return string.format(
    for _, item in ipairs(ingredients) do
'<div class="alchemy-collapse">' ..
        table.insert(parts, mw.html.create("div"):wikitext(item):allDone())
'<div class="alchemy-toggle" onclick="this.classList.toggle(\'open\')">%s</div>' ..
    end
'<div class="alchemy-content">%s</div>' ..
    return table.concat(parts, "\n")
'</div>',
end
title, content
)
end


local function renderEffect(text)
local recipeBlock = collapse('Рецепт', recipe)
    return mw.html.create("div"):addClass("alchemy-effect"):wikitext(text):allDone()
local effectBlock = collapse('Эффекты', effect)
end


local function renderRecipe(text)
return string.format([[
    return mw.html.create("div"):addClass("alchemy-recipe-block"):wikitext(text):allDone()
<div class="alchemy-block" style="border-color:%s">
end
<div class="alchemy-header" style="background:%s">%s</div>
 
<div class="alchemy-body">
function p.main(frame)
<div class="alchemy-product">%s</div>
    local args = frame:getParent().args
%s
 
%s
    local ingredients = {}
<div class="alchemy-description">%s</div>
    for k,v in pairs(args) do
</div>
        if k:match("^ingredient%d*$") then
</div>
            table.insert(ingredients, v)
]], color, color, name, product, recipeBlock, effectBlock, description)
        end
    end
 
    local result = args.result or "?"
    local effect = args.effect or ""
    local recipe = args.recipe or ""
 
    local html = mw.html.create("div")
        :addClass("alchemy-card")
 
    local content = mw.html.create("div")
        :addClass("alchemy-content")
        :css("display", "flex")
        :css("justify-content", "center")
        :css("align-items", "center")
 
    -- Левая колонка: ингредиенты вертикально
    local left = mw.html.create("div")
        :addClass("alchemy-ingredients")
        :css("display", "flex")
        :css("flex-direction", "column")
        :css("gap", "6px")
        :css("min-width", "150px")
        :wikitext(renderIngredients(ingredients))
 
    -- Центр: слово Смешайте
    local center = mw.html.create("div")
        :addClass("alchemy-mix")
        :css("margin", "0 20px")
        :css("font-weight", "bold")
        :css("color", darkColors.border)
        :wikitext("Смешайте")
 
    -- Правая колонка: результат
    local right = mw.html.create("div")
        :addClass("alchemy-result")
        :css("display", "flex")
        :css("flex-direction", "column")
        :css("gap", "10px")
 
    right:node(mw.html.create("div"):addClass("alchemy-result-name"):wikitext(result))
 
    if effect ~= "" then
        right:node(mw.html.create("div"):addClass("alchemy-effect-block"):wikitext(effect))
    end
 
    if recipe ~= "" then
        right:node(mw.html.create("div"):addClass("alchemy-recipe-block"):wikitext(recipe))
    end
 
    content
        :node(left)
        :node(center)
        :node(right)
 
    html
        :node(content)
 
    return tostring(html)
end
end


return p
return p

Текущая версия от 02:45, 17 июня 2025

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

local p = {}

function p.recipe(frame)
	local args = frame:getParent().args
	local name = args.name or 'Неизвестно'
	local color = args.color or '#cccccc'
	local product = args.product or ''
	local description = args.description or ''
	local effect = args.effect or ''
	local recipe = args.recipe or ''

	local function collapse(title, content)
		return string.format(
			'<div class="alchemy-collapse">' ..
				'<div class="alchemy-toggle" onclick="this.classList.toggle(\'open\')">%s</div>' ..
				'<div class="alchemy-content">%s</div>' ..
			'</div>',
			title, content
		)
	end

	local recipeBlock = collapse('Рецепт', recipe)
	local effectBlock = collapse('Эффекты', effect)

	return string.format([[
<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

return p