Модуль:Prototypes/Хранилище/Предмет: различия между версиями

Нет описания правки
Метка: ручная отмена
Нет описания правки
Метка: ручная отмена
Строка 3: Строка 3:
-- Кэш данных
-- Кэш данных
local dataCache = {}
local dataCache = {}
local indexCache = {}


-- Функция processRolls для преобразования диапазона
-- Функция processRolls для преобразования диапазона
Строка 40: Строка 41:
-- Создание хэш-таблицы для быстрого поиска по ID
-- Создание хэш-таблицы для быстрого поиска по ID
local function buildIndex(data)
local function buildIndex(data)
    if indexCache[data] then return indexCache[data] end
     if not data then return {} end
     if not data then return {} end
     local index = {}
     local index = {}
Строка 45: Строка 47:
         index[item.id] = item
         index[item.id] = item
     end
     end
    indexCache[data] = index
     return index
     return index
end
end
Строка 89: Строка 92:
-- Обработка вложенных таблиц
-- Обработка вложенных таблиц
processNestedSelectors = function(children)
processNestedSelectors = function(children)
     local result = {}
    if not children or #children == 0 then return "" end
 
    local results = {}
     local nestedCache = {}
 
     for _, child in ipairs(children) do
     for _, child in ipairs(children) do
         if child.id then
         if child.id then
             result[#result + 1] = formatContent(child)
             results[#results + 1] = formatContent(child)
         elseif child["!type"] == "NestedSelector" and child.tableId then
         elseif child["!type"] == "NestedSelector" then
            result[#result + 1] = handleNestedSelector(child, true)
            -- Кэшируем результат вызова handleNestedSelector
            if not nestedCache[child.tableId] then
                nestedCache[child.tableId] = handleNestedSelector(child, true)
            end
            results[#results + 1] = nestedCache[child.tableId]
         elseif child["!type"] == "GroupSelector" then
         elseif child["!type"] == "GroupSelector" then
             result[#result + 1] = handleGroupSelector(child)
             results[#results + 1] = handleGroupSelector(child)
         end
         end
     end
     end
     return table.concat(result)
 
     return table.concat(results)
end
end


Строка 266: Строка 278:
         local entity = findDataById(dataIndex, id)
         local entity = findDataById(dataIndex, id)
         if not entity then return 'ID не найден в данных.' end
         if not entity then return 'ID не найден в данных.' end
 
         if entity.EntityTableContainerFill then
         if entity.EntityTableContainerFill then
             local containers = entity.EntityTableContainerFill.containers
             local containers = entity.EntityTableContainerFill.containers
Строка 275: Строка 287:


         return 'Режим rolls не найден для этого ID.'
         return 'Режим rolls не найден для этого ID.'
    else
    else
         return 'Неизвестный режим: ' .. mode
         return 'Неизвестный режим: ' .. mode
     end
     end