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

мНет описания правки
мНет описания правки
Строка 34: Строка 34:
-- Локальные функции
-- Локальные функции
local findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector
local findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector
-- Функция для создания хэш-таблицы для быстрого поиска по ID
local function buildIndex(itemData)
    if not itemData then return {} end
    local index = {}
    for _, item in ipairs(itemData) do
        index[item.id] = item
    end
    return index
end


-- Поиск данных по ID через индекс
-- Поиск данных по ID через индекс
findDataById = function(itemDataIndex, id)
findDataById = function(itemDataIndex, id)
    if not itemDataIndex then return nil end
if not itemDataIndex then return nil end
for _, item in ipairs(itemDataIndex) do
for _, item in ipairs(itemDataIndex) do
if item.id == id then
if item.id == id then
Строка 53: Строка 43:
end
end
end
end
return nil
end
end


Строка 148: Строка 139:
     if not item then return '' end
     if not item then return '' end


     local result = {}
     local result = ""


     -- Обработка StorageFill
     -- Обработка StorageFill
     if item.StorageFill and item.StorageFill.contents then
     if item.StorageFill and item.StorageFill.contents then
         result[#result + 1] = getContentsOutput(item.StorageFill.contents)
         result = result getContentsOutput(item.StorageFill.contents)


     -- Обработка EntityTableContainerFill
     -- Обработка EntityTableContainerFill
Строка 161: Строка 152:
         if containers.entity_storage then
         if containers.entity_storage then
             if containers.entity_storage.children then
             if containers.entity_storage.children then
                 result[#result + 1] = processNestedSelectors(containers.entity_storage.children, visited)
                 result = result processNestedSelectors(containers.entity_storage.children, visited)
             end
             end
             if containers.entity_storage.tableId then
             if containers.entity_storage.tableId then
                 result[#result + 1] = getTableOutput(containers.entity_storage.tableId, visited)
                 result = result getTableOutput(containers.entity_storage.tableId, visited)
             end
             end
         end
         end
Строка 170: Строка 161:
         -- Обработка storagebase
         -- Обработка storagebase
         if containers.storagebase and containers.storagebase.tableId then
         if containers.storagebase and containers.storagebase.tableId then
             result[#result + 1] = getTableOutput(containers.storagebase.tableId, visited)
             result = result getTableOutput(containers.storagebase.tableId, visited)
         end
         end
     end
     end


     return table.concat(result)
     return result
end
end