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

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


function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args
     local args = frame.args
    if not next(args) then
        args = frame:getParent().args
    end
 


     local ingredients = {}
     local ingredients = {}

Версия от 23:54, 6 июня 2025

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

local p = {}

local darkColors = {
    border = "#338833",
    bg = "#101910",
    border2 = "#cc7744",
    bg2 = "#1a110a",
    border3 = "#2277cc",
    bg3 = "#0d1117"
}

local function renderIngredients(ingredients)
    local list = mw.html.create("ul"):addClass("alchemy-ingredient-list")
    for _, item in ipairs(ingredients) do
        list:tag("li"):wikitext(item)
    end
    return tostring(list)
end

function p.main(frame)
    local args = frame.args
    if not next(args) then
        args = frame:getParent().args
    end


    local ingredients = {}
    for k, v in pairs(args) do
        if k:match("^ingredient%d*$") then
            table.insert(ingredients, v)
        end
    end

    local result = args.result or "?"
    local effect = args.effect or ""
    local recipe = args.recipe or ""

    local card = mw.html.create("div")
        :addClass("alchemy-card")
        :css({
            ["border"] = "1px solid " .. darkColors.border,
            ["background-color"] = darkColors.bg,
            ["padding"] = "12px",
            ["margin"] = "8px",
            ["border-radius"] = "10px",
            ["width"] = "280px",
            ["box-shadow"] = "0 0 6px rgba(0,0,0,0.6)",
            ["display"] = "flex",
            ["flex-direction"] = "column",
            ["gap"] = "10px"
        })

    card:tag("div")
        :addClass("alchemy-result-name")
        :css("color", darkColors.border)
        :css("font-size", "18px")
        :css("font-weight", "bold")
        :wikitext(result)

    card:tag("div")
        :addClass("alchemy-ingredients")
        :wikitext(renderIngredients(ingredients))

    if recipe ~= "" then
        card:tag("div")
            :addClass("alchemy-recipe")
            :css("color", darkColors.border2)
            :wikitext("Способ: " .. recipe)
    end

    if effect ~= "" then
        card:tag("div")
            :addClass("alchemy-effect")
            :css("color", "#ccc")
            :wikitext(effect)
    end

    return tostring(card)
end

return p