Модуль: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


Строка 223: Строка 207:
         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 then
             if pack and pack.recipes then
                 local packRecipes = getPackRecipes(pack)
                 local packRecipes = pack.recipes
                 if #packRecipes > 0 then
                 if type(packRecipes) ~= "table" then
                     for _, recipeId in ipairs(packRecipes) do
                     packRecipes = { packRecipes }
                        local recipe = getRecipeDetails(recipeId)
                end
                        if recipe and recipe.result then
                for _, recipeId in ipairs(packRecipes) do
                    local recipe = getRecipeDetails(recipeId)
                    if recipe and recipe.result then
                        table.insert(recipes, {
                            result = recipe.result,
                            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 = recipe.result,
                                 result = reagentName .. "|amount=" .. amount .. "ед.|mode-chem=1",
                                 completetime = recipe.completetime,
                                 completetime = recipe.completetime,
                                 materials = recipe.materials,
                                 materials = recipe.materials,
Строка 236: Строка 232:
                                 tier = 0
                                 tier = 0
                             })
                             })
                        elseif recipe and recipe.resultReagents then
                             break
                             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
Строка 265: Строка 248:
         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 then
             if pack and pack.recipes then
                 local packRecipes = getPackRecipes(pack)
                 local packRecipes = pack.recipes
                 if #packRecipes > 0 then
                 if type(packRecipes) ~= "table" then
                     for _, recipeId in ipairs(packRecipes) do
                     packRecipes = { packRecipes }
                        local recipe = getRecipeDetails(recipeId)
                end
                        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,
                            end
                                researchName = researchInfo.name
                            })
                         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
Строка 297: Строка 279:
         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 then
             if pack and pack.recipes then
                 local packRecipes = getPackRecipes(pack)
                 local packRecipes = pack.recipes
                 if #packRecipes > 0 then
                 if type(packRecipes) ~= "table" then
                     for _, recipeId in ipairs(packRecipes) do
                     packRecipes = { packRecipes }
                        local recipe = getRecipeDetails(recipeId)
                end
                        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,
                        end
                            isEmag = true
                        })
                     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
Строка 326: Строка 307:
         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 then
             if pack and pack.recipes then
                 local packRecipes = getPackRecipes(pack)
                 local packRecipes = pack.recipes
                 if #packRecipes > 0 then
                 if type(packRecipes) ~= "table" then
                     for _, recipeId in ipairs(packRecipes) do
                     packRecipes = { packRecipes }
                        local recipe = getRecipeDetails(recipeId)
                end
                        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,
                            end
                                isEmag = true
                            })
                         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