Модуль:Песочница/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 = {}
    local initialTables = {}
for key, tblEntry in pairs(tableData) do
    for key, tblEntry in pairs(tableData) do
    if type(tblEntry) == "table" then
        if type(tblEntry) == "table" then
        if searchItemInStructure(tblEntry, targetId) then
            if searchItemInStructure(tblEntry, targetId) then
            local tableId = tblEntry.id or key
                local tableId = tblEntry.id or key
            table.insert(initialTables, tableId)
                table.insert(initialTables, tableId)
        end
            end
    end
        end
end
    end


     local allRelatedTables = {}
     local allRelatedTables = {}
Строка 114: Строка 113:


     local matchingStorages = {}
     local matchingStorages = {}
for storageId, storage in pairs(itemData) do
    for storageKey, storage in pairs(itemData) do
    if type(storage) == "table" then
        if type(storage) == "table" then
        local found = false
            local found = false
 
        if storage.EntityTableContainerFill  
            if storage.EntityTableContainerFill  
            and storage.EntityTableContainerFill.containers  
              and storage.EntityTableContainerFill.containers then
            and #allRelatedTables > 0 then
                if searchTableIdInStructure(storage.EntityTableContainerFill.containers, allRelatedTables) then
            if searchTableIdInStructure(storage.EntityTableContainerFill.containers, allRelatedTables) then
                    found = true
                found = true
                end
            end
            end
        end
 
            if searchItemInStructure(storage, targetId) then
        if searchItemInStructure(storage, targetId) then
                found = true
            found = true
            end
        end
 
            if found then
        if found then
                local actualId = storage.id or storageKey
            local actualId = storage.id or storageId
                table.insert(matchingStorages, actualId)
            table.insert(matchingStorages, actualId)
            end
        end
        end
    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 #matchingStorages == 0 then
     if #filteredStorages == 0 then
         return "Хранилище, содержащее предмет с id " .. targetId .. ", не найдено."
         return "Хранилище, содержащее предмет с id " .. targetId .. ", не найдено."
     end
     end


     return "Найденные хранилища: " .. table.concat(matchingStorages, ", ")
     return "Найденные хранилища: " .. table.concat(filteredStorages, ", ")
end
end