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

Материал из Space Stories Wiki
Нет описания правки
Нет описания правки
Строка 22: Строка 22:
             if trimmed ~= "" then
             if trimmed ~= "" then
                 count = count + 1
                 count = count + 1
                 table.insert(result, string.format(
                 local stepHtml = string.format(
                     '<div class="recipe-step">'..
                     '<div class="recipe-step">'..
                     '<input type="checkbox" id="step%d" disabled>'..
                     '<input type="checkbox" id="step%d" disabled>'..
                     '<label for="step%d">%s</label></div>',
                     '<label for="step%d">%s</label></div>',
                     count, count, mw.text.nowiki(trimmed)
                     count, count, mw.text.nowiki(trimmed)
                 ))
                 )
                table.insert(result, stepHtml)
             end
             end
         end
         end
Строка 33: Строка 34:
         -- Добавляем шаг смешивания
         -- Добавляем шаг смешивания
         if count > 0 then
         if count > 0 then
             table.insert(result, string.format(
             local mixHtml = string.format(
                 '<div class="recipe-step">'..
                 '<div class="recipe-step">'..
                 '<input type="checkbox" id="step-mix" disabled checked>'..
                 '<input type="checkbox" id="step-mix" disabled checked>'..
                 '<label for="step-mix">%s</label></div>',
                 '<label for="step-mix">%s</label></div>',
                 method
                 method
             ))
             )
            table.insert(result, mixHtml)
         end
         end
          
          
Строка 46: Строка 48:
     -- Генерация HTML
     -- Генерация HTML
     local html = {
     local html = {
         '<div class="alchemy-card">',
         '<div class="alchemy-card dark-theme">',
         '<h1 class="alchemy-title">' .. name .. '</h1>',
         '<h1 class="alchemy-title">' .. name .. '</h1>',
          
          
         '<div class="alchemy-section">',
         '<div class="alchemy-section">',
         '<div class="section-header" onclick="toggleSection(this)">',
         '<div class="section-header" onclick="toggleAlchemySection(this)">',
         '<span class="section-title">Рецепты</span>',
         '<span class="section-title">Рецепты</span>',
         '<span class="collapse-toggle">[свернуть]</span>',
         '<span class="collapse-toggle">[свернуть]</span>',
Строка 62: Строка 64:
          
          
         '<div class="alchemy-section">',
         '<div class="alchemy-section">',
         '<div class="section-header" onclick="toggleSection(this)">',
         '<div class="section-header" onclick="toggleAlchemySection(this)">',
         '<span class="section-title">Эффекты</span>',
         '<span class="section-title">Эффекты</span>',
         '<span class="collapse-toggle">[свернуть]</span>',
         '<span class="collapse-toggle">[свернуть]</span>',
Строка 71: Строка 73:
         '</div>',
         '</div>',
          
          
         '</div>', -- закрываем alchemy-card
         '</div>' -- закрываем alchemy-card
       
        -- JavaScript для сворачивания
        [[<script>
        function toggleSection(header) {
            const content = header.nextElementSibling;
            const toggle = header.querySelector('.collapse-toggle');
            if (content.style.display === "none") {
                content.style.display = "block";
                toggle.textContent = "[свернуть]";
            } else {
                content.style.display = "none";
                toggle.textContent = "[развернуть]";
            }
        }
        </script>]]
     }
     }
      
      

Версия от 11:31, 22 июня 2025

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

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    
    -- Обработка параметров
    local name = mw.text.killMarkers(args.name or "Без названия")
    local recipe = args.recipe or ""
    local effects = frame:preprocess(args.effects or "Нет описания.")
    local method = (recipe ~= "" and "Смешайте") or "Неизвестно"

    -- Функция для форматирования реагентов с чекбоксами
    local function formatReagents(input)
        if input == "" then return "" end
        
        local result = {}
        local count = 0
        
        -- Обрабатываем каждый элемент рецепта
        for item in mw.text.gsplit(input, ",") do
            local trimmed = mw.text.trim(item)
            if trimmed ~= "" then
                count = count + 1
                local stepHtml = string.format(
                    '<div class="recipe-step">'..
                    '<input type="checkbox" id="step%d" disabled>'..
                    '<label for="step%d">%s</label></div>',
                    count, count, mw.text.nowiki(trimmed)
                )
                table.insert(result, stepHtml)
            end
        end
        
        -- Добавляем шаг смешивания
        if count > 0 then
            local mixHtml = string.format(
                '<div class="recipe-step">'..
                '<input type="checkbox" id="step-mix" disabled checked>'..
                '<label for="step-mix">%s</label></div>',
                method
            )
            table.insert(result, mixHtml)
        end
        
        return table.concat(result)
    end

    -- Генерация HTML
    local html = {
        '<div class="alchemy-card dark-theme">',
        '<h1 class="alchemy-title">' .. name .. '</h1>',
        
        '<div class="alchemy-section">',
        '<div class="section-header" onclick="toggleAlchemySection(this)">',
        '<span class="section-title">Рецепты</span>',
        '<span class="collapse-toggle">[свернуть]</span>',
        '</div>',
        '<div class="section-content">',
        formatReagents(recipe),
        '</div>',
        '</div>',
        
        '<hr class="alchemy-divider">',
        
        '<div class="alchemy-section">',
        '<div class="section-header" onclick="toggleAlchemySection(this)">',
        '<span class="section-title">Эффекты</span>',
        '<span class="collapse-toggle">[свернуть]</span>',
        '</div>',
        '<div class="section-content">',
        effects,
        '</div>',
        '</div>',
        
        '</div>' -- закрываем alchemy-card
    }
    
    return table.concat(html)
end

return p