Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) Нет описания правки Метка: ручная отмена |
Pok (обсуждение | вклад) Нет описания правки Метка: ручная отмена |
||
| Строка 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 | 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 | ||
results[#results + 1] = formatContent(child) | |||
elseif child["!type"] == "NestedSelector" | elseif child["!type"] == "NestedSelector" then | ||
-- Кэшируем результат вызова 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 | ||
results[#results + 1] = handleGroupSelector(child) | |||
end | end | ||
end | end | ||
return table.concat( | |||
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 | |||
return 'Неизвестный режим: ' .. mode | return 'Неизвестный режим: ' .. mode | ||
end | end | ||