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

Нет описания правки
мНет описания правки
Строка 77: Строка 77:
     end
     end
     return nil
     return nil
end
-----------------------------------------------------------
-- Функция, гарантирующая, что список рецептов пакета – таблица
-----------------------------------------------------------
local function getPackRecipes(pack)
    if not pack then
        return {}
    end
    if type(pack.recipes) == "table" then
        return pack.recipes
    elseif type(pack.recipes) == "string" then
        return { pack.recipes }
    else
        return {}
    end
end
end


Строка 203: Строка 219:
     end
     end


     -- Обработка staticPacks
     -- Обработка staticPacks (новый формат)
     if lathe.Lathe and lathe.Lathe.staticPacks then
     if lathe.Lathe and lathe.Lathe.staticPacks then
         for _, packId in ipairs(lathe.Lathe.staticPacks) do
         for _, packId in ipairs(lathe.Lathe.staticPacks) do
             local pack = getRecipePackDetails(packId)
             local pack = getRecipePackDetails(packId)
             if pack and pack.recipes then
             if pack then
                for _, recipeId in ipairs(pack.recipes) do
                local packRecipes = getPackRecipes(pack)
                    local recipe = getRecipeDetails(recipeId)
                if #packRecipes > 0 then
                    if recipe and recipe.result then
                    for _, recipeId in ipairs(packRecipes) do
                        table.insert(recipes, {
                        local recipe = getRecipeDetails(recipeId)
                            result = recipe.result,
                        if recipe and recipe.result then
                            completetime = recipe.completetime,
                            materials = recipe.materials,
                            discipline = "Static",
                            tier = 0
                        })
                    elseif recipe and recipe.resultReagents then
                        for reagent, amount in pairs(recipe.resultReagents) do
                            local reagentName = chemMapping[reagent] or reagent
                             table.insert(recipes, {
                             table.insert(recipes, {
                                 result = reagentName .. "|amount=" .. amount .. "ед.|mode-chem=1",
                                 result = recipe.result,
                                 completetime = recipe.completetime,
                                 completetime = recipe.completetime,
                                 materials = recipe.materials,
                                 materials = recipe.materials,
Строка 228: Строка 236:
                                 tier = 0
                                 tier = 0
                             })
                             })
                             break
                        elseif recipe and recipe.resultReagents then
                             for reagent, amount in pairs(recipe.resultReagents) do
                                local reagentName = chemMapping[reagent] or reagent
                                table.insert(recipes, {
                                    result = reagentName .. "|amount=" .. amount .. "ед.|mode-chem=1",
                                    completetime = recipe.completetime,
                                    materials = recipe.materials,
                                    discipline = "Static",
                                    tier = 0
                                })
                                break
                            end
                        else
                            out = out .. '<div style="color:red;">Ошибка: Рецепт с ID "' .. recipeId .. '" не найден или поля result/resultReagents отсутствуют.</div>'
                         end
                         end
                    else
                        out = out .. '<div style="color:red;">Ошибка: Рецепт с ID "' .. recipeId .. '" не найден или поля result/resultReagents отсутствуют.</div>'
                     end
                     end
                else
                    out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не содержит рецепты.</div>'
                 end
                 end
             else
             else
                 out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не найден или не содержит рецепты.</div>'
                 out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не найден.</div>'
             end
             end
         end
         end
     end
     end


     -- Обработка dynamicPacks
     -- Обработка dynamicPacks (новый формат)
     if lathe.Lathe and lathe.Lathe.dynamicPacks then
     if lathe.Lathe and lathe.Lathe.dynamicPacks then
         for _, packId in ipairs(lathe.Lathe.dynamicPacks) do
         for _, packId in ipairs(lathe.Lathe.dynamicPacks) do
             local pack = getRecipePackDetails(packId)
             local pack = getRecipePackDetails(packId)
             if pack and pack.recipes then
             if pack then
                for _, recipeId in ipairs(pack.recipes) do
                local packRecipes = getPackRecipes(pack)
                    local recipe = getRecipeDetails(recipeId)
                if #packRecipes > 0 then
                    if recipe then
                    for _, recipeId in ipairs(packRecipes) do
                        local researchInfo = findInResearch(recipeId)
                        local recipe = getRecipeDetails(recipeId)
                        if researchInfo then
                        if recipe then
                            table.insert(recipes, {
                            local researchInfo = findInResearch(recipeId)
                                result = recipe.result,
                            if researchInfo then
                                completetime = recipe.completetime,
                                table.insert(recipes, {
                                materials = recipe.materials,
                                    result = recipe.result,
                                discipline = researchInfo.discipline,
                                    completetime = recipe.completetime,
                                tier = researchInfo.tier,
                                    materials = recipe.materials,
                                researchName = researchInfo.name
                                    discipline = researchInfo.discipline,
                            })
                                    tier = researchInfo.tier,
                                    researchName = researchInfo.name
                                })
                            end
                         end
                         end
                     end
                     end
                else
                    out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не содержит рецепты.</div>'
                 end
                 end
             else
             else
                 out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не найден или не содержит рецепты.</div>'
                 out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не найден.</div>'
             end
             end
         end
         end
     end
     end


     -- Обработка emagStaticPacks
     -- Обработка emagStaticPacks (новый формат)
     if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagStaticPacks then
     if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagStaticPacks then
         for _, packId in ipairs(lathe.EmagLatheRecipes.emagStaticPacks) do
         for _, packId in ipairs(lathe.EmagLatheRecipes.emagStaticPacks) do
             local pack = getRecipePackDetails(packId)
             local pack = getRecipePackDetails(packId)
             if pack and pack.recipes then
             if pack then
                for _, recipeId in ipairs(pack.recipes) do
                local packRecipes = getPackRecipes(pack)
                    local recipe = getRecipeDetails(recipeId)
                if #packRecipes > 0 then
                    if recipe then
                    for _, recipeId in ipairs(packRecipes) do
                        table.insert(recipes, {
                        local recipe = getRecipeDetails(recipeId)
                            result = recipe.result,
                        if recipe then
                            completetime = recipe.completetime,
                            table.insert(recipes, {
                            materials = recipe.materials,
                                result = recipe.result,
                            discipline = "Static",
                                completetime = recipe.completetime,
                            tier = 0,
                                materials = recipe.materials,
                            isEmag = true
                                discipline = "Static",
                        })
                                tier = 0,
                                isEmag = true
                            })
                        end
                     end
                     end
                else
                    out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не содержит рецепты.</div>'
                 end
                 end
             else
             else
                 out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не найден или не содержит рецепты.</div>'
                 out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не найден.</div>'
             end
             end
         end
         end
     end
     end


     -- Обработка emagDynamicPacks
     -- Обработка emagDynamicPacks (новый формат)
     if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagDynamicPacks then
     if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagDynamicPacks then
         for _, packId in ipairs(lathe.EmagLatheRecipes.emagDynamicPacks) do
         for _, packId in ipairs(lathe.EmagLatheRecipes.emagDynamicPacks) do
             local pack = getRecipePackDetails(packId)
             local pack = getRecipePackDetails(packId)
             if pack and pack.recipes then
             if pack then
                for _, recipeId in ipairs(pack.recipes) do
                local packRecipes = getPackRecipes(pack)
                    local recipe = getRecipeDetails(recipeId)
                if #packRecipes > 0 then
                    if recipe then
                    for _, recipeId in ipairs(packRecipes) do
                        local researchInfo = findInResearch(recipeId)
                        local recipe = getRecipeDetails(recipeId)
                        if researchInfo then
                        if recipe then
                            table.insert(recipes, {
                            local researchInfo = findInResearch(recipeId)
                                result = recipe.result,
                            if researchInfo then
                                completetime = recipe.completetime,
                                table.insert(recipes, {
                                materials = recipe.materials,
                                    result = recipe.result,
                                discipline = researchInfo.discipline,
                                    completetime = recipe.completetime,
                                tier = researchInfo.tier,
                                    materials = recipe.materials,
                                researchName = researchInfo.name,
                                    discipline = researchInfo.discipline,
                                isEmag = true
                                    tier = researchInfo.tier,
                            })
                                    researchName = researchInfo.name,
                                    isEmag = true
                                })
                            end
                         end
                         end
                     end
                     end
                else
                    out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не содержит рецепты.</div>'
                 end
                 end
             else
             else
                 out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не найден или не содержит рецепты.</div>'
                 out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не найден.</div>'
             end
             end
         end
         end