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

Нет описания правки
мНет описания правки
Строка 36: Строка 36:


-- Функция для сортировки рецептов
-- Функция для сортировки рецептов
local function sortRecipesByPriority(recipes)
local function sortRecipesByDisciplineAndTier(recipes)
     table.sort(recipes, function(a, b)
     table.sort(recipes, function(a, b)
         local priority = { Static = 1, Unknown = 2 }
         if a.discipline == b.discipline then
        local aPriority = priority[a.discipline] or 3
            return a.tier < b.tier
        local bPriority = priority[b.discipline] or 3
 
        if aPriority == bPriority then
            if a.discipline == b.discipline then
                return a.tier < b.tier
            end
            return a.discipline < b.discipline
         end
         end
         return aPriority < bPriority
         return a.discipline < b.discipline
     end)
     end)
end
end
Строка 78: Строка 71:


     local recipes = {}
     local recipes = {}
    local emagRecipes = {}


     local function getRecipeDetails(recipeId)
     local function getRecipeDetails(recipeId)
Строка 145: Строка 139:
                     })
                     })
                 end
                 end
            end
        end
    end
    -- Обработка emagStaticRecipes
    if lathe.EmagLatheRecipes and lathe.EmagLatheRecipes.emagStaticRecipes then
        for _, recipeId in ipairs(lathe.EmagLatheRecipes.emagStaticRecipes) do
            local recipe = getRecipeDetails(recipeId)
            if recipe then
                table.insert(emagRecipes, {
                    result = recipe.result,
                    completetime = recipe.completetime,
                    materials = recipe.materials
                })
             end
             end
         end
         end
Строка 150: Строка 158:


     -- Сортировка рецептов
     -- Сортировка рецептов
     sortRecipesByPriority(recipes)
     sortRecipesByDisciplineAndTier(recipes)


     -- Вывод рецептов
     -- Вывод рецептов
Строка 166: Строка 174:
         end
         end
         output = output .. '</li>'
         output = output .. '</li>'
    end
    -- Вывод emagStaticRecipes
    if #emagRecipes > 0 then
        output = output .. '<li><strong>Дополнительный ассортимент (EMAG):</strong></li>'
        for _, recipe in ipairs(emagRecipes) do
            output = output .. '<li>' .. recipe.result
            output = output .. ' (Время изготовления: ' .. format_seconds_to_short_string(recipe.completetime) .. ')'
            output = output .. '<ul>'
            for material, amount in pairs(recipe.materials) do
                output = output .. '<li>' .. material .. ': ' .. amount .. '</li>'
            end
            output = output .. '</ul>'
            output = output .. '<div><strong>EMAG</strong></div>'
            output = output .. '</li>'
        end
     end
     end