Модуль:Местонахождение: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 19: | Строка 19: | ||
local latheData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe.json/data") | local latheData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe.json/data") | ||
local recipeData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipes.json/data") | local recipeData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipes.json/data") | ||
local recipePackData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipe pack.json/data") | |||
local researchData = mw.loadData("Модуль:IanComradeBot/prototypes/research.json/data") | local researchData = mw.loadData("Модуль:IanComradeBot/prototypes/research.json/data") | ||
local materialData = mw.loadData("Модуль:IanComradeBot/prototypes/materials.json/data") | local materialData = mw.loadData("Модуль:IanComradeBot/prototypes/materials.json/data") | ||
| Строка 311: | Строка 312: | ||
function p.reverseLathe(frame) | function p.reverseLathe(frame) | ||
local | local targetRecipe = frame.args[2] | ||
if not | if not targetRecipe or targetRecipe == "" then | ||
return "Ошибка: не указан результат рецепта для обратного поиска." | return "Ошибка: не указан результат рецепта для обратного поиска." | ||
end | end | ||
local | local matchingPacks = {} | ||
local function | for _, pack in ipairs(recipePackData) do | ||
for _, | if pack.recipes then | ||
for _, recipe in ipairs(pack.recipes) do | |||
if recipe == targetRecipe then | |||
table.insert(matchingPacks, pack.id) | |||
break | |||
end | |||
end | |||
end | |||
end | |||
if #matchingPacks == 0 then | |||
return "" | |||
end | |||
local function containsAny(array, targets) | |||
for _, v in ipairs(array or {}) do | |||
for _, t in ipairs(targets) do | |||
if v == t then | |||
return true | |||
end | |||
end | end | ||
end | end | ||
| Строка 327: | Строка 344: | ||
end | end | ||
local matchingLathes = {} | |||
for _, lathe in ipairs(latheData) do | for _, lathe in ipairs(latheData) do | ||
local found = false | local found = false | ||
if lathe.Lathe then | if lathe.Lathe then | ||
if | if containsAny(lathe.Lathe.staticPacks, matchingPacks) or containsAny(lathe.Lathe.dynamicPacks, matchingPacks) then | ||
found = true | found = true | ||
end | end | ||
end | end | ||
if not found and lathe.EmagLatheRecipes then | if not found and lathe.EmagLatheRecipes then | ||
if | if containsAny(lathe.EmagLatheRecipes.emagStaticRecipes, matchingPacks) or containsAny(lathe.EmagLatheRecipes.emagDynamicPacks, matchingPacks) then | ||
found = true | found = true | ||
end | end | ||