Модуль:Prototypes/Машина/Станок: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 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 | if pack then | ||
local packRecipes = getPackRecipes(pack) | |||
if #packRecipes > 0 then | |||
for _, recipeId in ipairs(packRecipes) do | |||
local recipe = getRecipeDetails(recipeId) | |||
if recipe and recipe.result then | |||
table.insert(recipes, { | table.insert(recipes, { | ||
result = | 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 | ||
end | end | ||
else | |||
out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не содержит рецепты.</div>' | |||
end | end | ||
else | else | ||
out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не найден | 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 | if pack then | ||
local packRecipes = getPackRecipes(pack) | |||
if #packRecipes > 0 then | |||
for _, recipeId in ipairs(packRecipes) do | |||
local recipe = getRecipeDetails(recipeId) | |||
if recipe then | |||
local researchInfo = findInResearch(recipeId) | |||
if researchInfo then | |||
table.insert(recipes, { | |||
result = recipe.result, | |||
completetime = recipe.completetime, | |||
materials = recipe.materials, | |||
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 .. '" не найден | 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 | if pack then | ||
local packRecipes = getPackRecipes(pack) | |||
if #packRecipes > 0 then | |||
for _, recipeId in ipairs(packRecipes) do | |||
local recipe = getRecipeDetails(recipeId) | |||
if recipe then | |||
table.insert(recipes, { | |||
result = recipe.result, | |||
completetime = recipe.completetime, | |||
materials = recipe.materials, | |||
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 .. '" не найден | 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 | if pack then | ||
local packRecipes = getPackRecipes(pack) | |||
if #packRecipes > 0 then | |||
for _, recipeId in ipairs(packRecipes) do | |||
local recipe = getRecipeDetails(recipeId) | |||
if recipe then | |||
local researchInfo = findInResearch(recipeId) | |||
if researchInfo then | |||
table.insert(recipes, { | |||
result = recipe.result, | |||
completetime = recipe.completetime, | |||
materials = recipe.materials, | |||
discipline = researchInfo.discipline, | |||
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 .. '" не найден | out = out .. '<div style="color:red;">Ошибка: Пакет рецептов с ID "' .. packId .. '" не найден.</div>' | ||
end | end | ||
end | end | ||