Модуль:Prototypes/Машина/Станок: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 35: | Строка 35: | ||
end | end | ||
-- Функция для сортировки | -- Функция для сортировки рецептов | ||
local function | local function sortRecipesByDisciplineAndTier(recipes) | ||
table.sort(recipes, function(a, b) | |||
if a.discipline == b.discipline then | |||
return a.tier < b.tier | |||
end | end | ||
return a.discipline < b.discipline | |||
end) | |||
end | end | ||
| Строка 82: | Строка 69: | ||
local output = '<h3>Рецепты станка: ' .. latheId .. '</h3>' | local output = '<h3>Рецепты станка: ' .. latheId .. '</h3>' | ||
output = output .. '<ul>' | output = output .. '<ul>' | ||
local recipes = {} | |||
local function getRecipeDetails(recipeId) | local function getRecipeDetails(recipeId) | ||
| Строка 108: | Строка 97: | ||
return nil | return nil | ||
end | end | ||
-- Обработка staticRecipes | -- Обработка staticRecipes | ||
if lathe.Lathe.staticRecipes then | if lathe.Lathe.staticRecipes then | ||
for _, recipeId in ipairs(lathe.Lathe.staticRecipes) do | for _, recipeId in ipairs(lathe.Lathe.staticRecipes) do | ||
local recipe = getRecipeDetails(recipeId) | local recipe = getRecipeDetails(recipeId) | ||
if recipe then | if recipe then | ||
table.insert(recipes, { | |||
result = recipe.result, | |||
completetime = recipe.completetime, | |||
materials = recipe.materials, | |||
discipline = "Static", | |||
tier = 0 | |||
}) | |||
end | end | ||
end | end | ||
| Строка 132: | Строка 116: | ||
-- Обработка dynamicRecipes | -- Обработка dynamicRecipes | ||
if lathe.Lathe.dynamicRecipes then | if lathe.Lathe.dynamicRecipes then | ||
for _, recipeId in ipairs(lathe.Lathe.dynamicRecipes) do | for _, recipeId in ipairs(lathe.Lathe.dynamicRecipes) do | ||
local recipe = getRecipeDetails(recipeId) | local recipe = getRecipeDetails(recipeId) | ||
| Строка 138: | Строка 121: | ||
local researchInfo = findInResearch(recipeId) | local researchInfo = findInResearch(recipeId) | ||
if researchInfo then | if researchInfo then | ||
table.insert(recipes, { | |||
result = recipe.result, | |||
completetime = recipe.completetime, | |||
materials = recipe.materials, | |||
discipline = researchInfo.discipline, | |||
tier = researchInfo.tier, | |||
researchName = researchInfo.name | |||
}) | |||
else | else | ||
table.insert(recipes, { | |||
result = recipe.result, | |||
completetime = recipe.completetime, | |||
materials = recipe.materials, | |||
discipline = "Unknown", | |||
tier = 0 | |||
}) | |||
end | end | ||
end | end | ||
| Строка 162: | Строка 142: | ||
end | end | ||
-- | -- Сортировка рецептов | ||
sortRecipesByDisciplineAndTier(recipes) | |||
for | |||
output = output .. '<li | -- Вывод рецептов | ||
for _, recipe in ipairs(recipes) do | |||
output = output .. '<li>' .. recipe.result | |||
output = output .. ' (Время изготовления: ' .. format_seconds_to_short_string(recipe.completetime) .. ')' | |||
output = output .. '<ul>' | output = output .. '<ul>' | ||
for material, amount in pairs(recipe.materials) do | |||
for | output = output .. '<li>' .. material .. ': ' .. amount .. '</li>' | ||
output = output .. '<li>' .. | |||
end | end | ||
output = output .. '</ul>' | output = output .. '</ul>' | ||
if recipe.discipline ~= "Static" and recipe.discipline ~= "Unknown" then | |||
output = output .. '<div>Исследование: ' .. recipe.discipline .. ' - ' .. recipe.researchName | |||
output = output .. ' (Уровень: ' .. recipe.tier .. ')</div>' | |||
end | |||
output = output .. '</li>' | |||
end | end | ||