Модуль:Prototypes/Машина/Станок: различия между версиями

мНет описания правки
мНет описания правки
Строка 220: Строка 220:
-- Функция для формирования строки рецепта
-- Функция для формирования строки рецепта
-----------------------------------------------------------
-----------------------------------------------------------
local function formatRecipe(recipe, timeMultiplier, materialUseMultiplier, itemMode)
local function formatRecipe(recipe, timeMultiplier, materialUseMultiplier)
     local out = ""
     local out = ""
     local scaledTime = recipe.completetime * timeMultiplier
     local scaledTime = recipe.completetime * timeMultiplier
     out = out .. '{{Шаблон:Prototypes/Машина/Станок|product=' .. recipe.result
     out = out .. '{{Шаблон:Prototypes/Машина/Станок|product=' .. recipe.result
    if itemMode then
        out = out .. '|no-product=1'
    end
     out = out .. '|complete-time={{#invoke:Code/Формат/Время|main|seconds|' .. scaledTime .. '}}|materials='
     out = out .. '|complete-time={{#invoke:Code/Формат/Время|main|seconds|' .. scaledTime .. '}}|materials='


Строка 308: Строка 305:
         local materialUseMultiplier = (lathe.Lathe and lathe.Lathe.materialUseMultiplier) or 1
         local materialUseMultiplier = (lathe.Lathe and lathe.Lathe.materialUseMultiplier) or 1
         local timeMultiplier = (lathe.Lathe and lathe.Lathe.timeMultiplier) or 1
         local timeMultiplier = (lathe.Lathe and lathe.Lathe.timeMultiplier) or 1
        local matchingRecipes = {}


         for _, recipe in ipairs(recipes) do
         for _, recipe in ipairs(recipes) do
             if recipe.id == itemId or recipe.result == itemId then
             if recipe.id == itemId or recipe.result == itemId then
                 table.insert(matchingRecipes, recipe)
                 foundAny = true
            end
                 local recipeStr = formatRecipe(recipe, timeMultiplier, materialUseMultiplier)
        end
 
        if #matchingRecipes > 0 then
            foundAny = true
            out = out .. '<div class="lathe-grid">'
            for _, recipe in ipairs(matchingRecipes) do
                -- Формируем строку рецепта без параметра no-product (itemMode = false)
                 local recipeStr = formatRecipe(recipe, timeMultiplier, materialUseMultiplier, false)
                -- Добавляем параметр method-container с id станка
                 recipeStr = recipeStr:gsub("}}$", "|method-container=" .. lathe.id .. "}}")
                 recipeStr = recipeStr:gsub("}}$", "|method-container=" .. lathe.id .. "}}")
                 out = out .. recipeStr
                 out = out .. '<div class="grid-item-adaptive">' .. recipeStr .. '</div>'
             end
             end
            out = out .. '</div>'
         end
         end
     end
     end
Строка 353: Строка 339:
         local materialUseMultiplier = (lathe.Lathe and lathe.Lathe.materialUseMultiplier) or 1
         local materialUseMultiplier = (lathe.Lathe and lathe.Lathe.materialUseMultiplier) or 1
         local timeMultiplier = (lathe.Lathe and lathe.Lathe.timeMultiplier) or 1
         local timeMultiplier = (lathe.Lathe and lathe.Lathe.timeMultiplier) or 1
        local matchingRecipes = {}


         for _, recipe in ipairs(recipes) do
         for _, recipe in ipairs(recipes) do
Строка 359: Строка 344:
                 for matId, _ in pairs(recipe.materials) do
                 for matId, _ in pairs(recipe.materials) do
                     if matId == materialId then
                     if matId == materialId then
                         table.insert(matchingRecipes, recipe)
                         foundAny = true
                        local recipeStr = formatRecipe(recipe, timeMultiplier, materialUseMultiplier)
                        recipeStr = recipeStr:gsub("}}$", "|method-container=" .. lathe.id .. "}}")
                        out = out .. '<div class="grid-item-adaptive">' .. recipeStr .. '</div>'
                         break
                         break
                     end
                     end
                 end
                 end
             end
             end
        end
        if #matchingRecipes > 0 then
            foundAny = true
            out = out .. '<div class="lathe-grid">'
            for _, recipe in ipairs(matchingRecipes) do
                local recipeStr = formatRecipe(recipe, timeMultiplier, materialUseMultiplier, false)
                recipeStr = recipeStr:gsub("}}$", "|method-container=" .. lathe.id .. "}}")
                out = out .. recipeStr
            end
            out = out .. '</div>'
         end
         end
     end
     end