Модуль:Песочница/Pok: различия между версиями

мНет описания правки
мНет описания правки
Строка 44: Строка 44:


---------------------------------------------------------------------
---------------------------------------------------------------------
local function findRelatedTables(initialList)
local function searchTableIdInStructure(struct, tableIds)
     local results = {}
     if type(struct) ~= "table" then
     local function recursiveSearch(tblId)
        return false
        if results[tblId] then  
     end
             return
    if struct.tableId then
        for _, tid in ipairs(tableIds) do
            if struct.tableId == tid then
                return true
             end
         end
         end
        results[tblId] = true
    end
        for id, entry in pairs(tableData) do
    for _, v in pairs(struct) do
            if type(entry) == "table" then
        if type(v) == "table" then
                for _, value in pairs(entry) do
            if searchTableIdInStructure(v, tableIds) then
                    if type(value) == "table" and value.tableId and value.tableId == tblId then
                 return true
                        recursiveSearch(id)
                    end
                 end
             end
             end
         end
         end
     end
     end
    for _, tblId in ipairs(initialList) do
     return false
        recursiveSearch(tblId)
    end
    local res = {}
    for id in pairs(results) do
        table.insert(res, id)
    end
     return res
end
end


Строка 94: Строка 88:
     local matchingStorages = {}
     local matchingStorages = {}
     for storageId, storage in pairs(itemData) do
     for storageId, storage in pairs(itemData) do
         if type(storage) == "table" and storage.EntityTableContainerFill and storage.EntityTableContainerFill.containers then
         if type(storage) == "table" then
            local containers = storage.EntityTableContainerFill.containers
            local found = false
            if containers.entity_storage and containers.entity_storage.tableId then
            if storage.EntityTableContainerFill and storage.EntityTableContainerFill.containers then
                for _, tblId in ipairs(allRelatedTables) do
                if searchTableIdInStructure(storage.EntityTableContainerFill.containers, allRelatedTables) then
                     if containers.entity_storage.tableId == tblId then
                     found = true
                        table.insert(matchingStorages, storageId)
                    end
                 end
                 end
             end
             end
             if containers.storagebase and containers.storagebase.tableId then
             if storage.id and storage.id == targetId then
                 for _, tblId in ipairs(allRelatedTables) do
                 found = true
                    if containers.storagebase.tableId == tblId then
            end
                        table.insert(matchingStorages, storageId)
            if found then
                    end
                table.insert(matchingStorages, storageId)
                end
             end
             end
        end
        if storage.id and storage.id == targetId then
            table.insert(matchingStorages, storageId)
         end
         end
     end
     end