Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 70: | Строка 70: | ||
return res | return res | ||
end | end | ||
local function searchTableIdInStructure(struct, tableIds) | local function searchTableIdInStructure(struct, tableIds) | ||
if type(struct) ~= "table" then | if type(struct) ~= "table" then | ||
| Строка 98: | Строка 97: | ||
end | end | ||
local initialTables = {} | |||
for key, tblEntry in pairs(tableData) do | |||
if type(tblEntry) == "table" then | |||
if searchItemInStructure(tblEntry, targetId) then | |||
local tableId = tblEntry.id or key | |||
table.insert(initialTables, tableId) | |||
end | |||
end | |||
end | |||
local allRelatedTables = {} | local allRelatedTables = {} | ||
| Строка 114: | Строка 113: | ||
local matchingStorages = {} | local matchingStorages = {} | ||
for storageKey, storage in pairs(itemData) do | |||
if type(storage) == "table" then | |||
local found = false | |||
if storage.EntityTableContainerFill | |||
and storage.EntityTableContainerFill.containers then | |||
if searchTableIdInStructure(storage.EntityTableContainerFill.containers, allRelatedTables) then | |||
found = true | |||
end | |||
end | |||
if searchItemInStructure(storage, targetId) then | |||
found = true | |||
end | |||
if found then | |||
local actualId = storage.id or storageKey | |||
table.insert(matchingStorages, actualId) | |||
end | |||
end | |||
end | |||
local filteredStorages = {} | |||
for _, sid in ipairs(matchingStorages) do | |||
local skip = false | |||
for _, cargo in pairs(cargoData) do | |||
if type(cargo) == "table" and cargo.product == sid then | |||
skip = true | |||
break | |||
end | |||
end | |||
if not skip then | |||
table.insert(filteredStorages, sid) | |||
end | |||
end | |||
if # | if #filteredStorages == 0 then | ||
return "Хранилище, содержащее предмет с id " .. targetId .. ", не найдено." | return "Хранилище, содержащее предмет с id " .. targetId .. ", не найдено." | ||
end | end | ||
return "Найденные хранилища: " .. table.concat( | return "Найденные хранилища: " .. table.concat(filteredStorages, ", ") | ||
end | end | ||