Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) Нет описания правки Метка: ручная отмена |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 4: | Строка 4: | ||
local dataCache = {} | local dataCache = {} | ||
local indexCache = {} | local indexCache = {} | ||
local tableCache = {} | |||
local containedCache = {} | |||
local chemCache = {} | |||
local processRollsCache = {} | |||
-- Функция processRolls для преобразования диапазона | -- Функция processRolls для преобразования диапазона с кэшированием | ||
local processRolls = function(rolls) | local processRolls = function(rolls) | ||
if processRollsCache[rolls] then return processRollsCache[rolls] end | |||
local result = {} | local result = {} | ||
if rolls and rolls.range then | if rolls and rolls.range then | ||
local min, max = rolls.range:match("(%d+),%s*(%d+)") | local min, max = rolls.range:match("(%d+),%s*(%d+)") | ||
min, max = tonumber(min), tonumber(max) | min, max = tonumber(min), tonumber(max) | ||
| Строка 18: | Строка 23: | ||
end | end | ||
elseif rolls and rolls.value then | elseif rolls and rolls.value then | ||
result[#result + 1] = string.format('Будет сгенерировано %d предметов.', rolls.value) | result[#result + 1] = string.format('Будет сгенерировано %d предметов.', rolls.value) | ||
else | else | ||
result[#result + 1] = 'Не указан параметр rolls.' | result[#result + 1] = 'Не указан параметр rolls.' | ||
end | end | ||
processRollsCache[rolls] = table.concat(result) | |||
return processRollsCache[rolls] | |||
end | end | ||
| Строка 83: | Строка 89: | ||
-- Получение содержимого через таблицу | -- Получение содержимого через таблицу | ||
getContentsOutput = function(contents) | getContentsOutput = function(contents) | ||
local cacheKey = table.concat(contents, ",") | |||
if containedCache[cacheKey] then return containedCache[cacheKey] end | |||
local result = {} | local result = {} | ||
for _, content in ipairs(contents) do | for _, content in ipairs(contents) do | ||
result[#result + 1] = formatContent(content) | result[#result + 1] = formatContent(content) | ||
end | end | ||
containedCache[cacheKey] = table.concat(result) | |||
return containedCache[cacheKey] | |||
end | end | ||
| Строка 116: | Строка 127: | ||
-- Обработка таблиц | -- Обработка таблиц | ||
getTableOutput = function(tableId) | getTableOutput = function(tableId) | ||
if tableCache[tableId] then return tableCache[tableId] end | |||
local allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json') | local allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json') | ||
local tableData = findDataById(buildIndex(allSelectors), tableId) | local tableData = findDataById(buildIndex(allSelectors), tableId) | ||
if not tableData then | if not tableData then | ||
tableCache[tableId] = 'Таблица не найдена.' | |||
return tableCache[tableId] | |||
end | |||
if tableData['!type:GroupSelector'] then | if tableData['!type:GroupSelector'] then | ||
tableCache[tableId] = handleGroupSelector(tableData['!type:GroupSelector']) | |||
elseif tableData['!type:AllSelector'] then | elseif tableData['!type:AllSelector'] then | ||
tableCache[tableId] = processNestedSelectors(tableData['!type:AllSelector'].children) | |||
else | |||
tableCache[tableId] = 'Таблица не содержит элементов.' | |||
end | end | ||
return | return tableCache[tableId] | ||
end | end | ||
| Строка 232: | Строка 250: | ||
-- Формирование списка химии | -- Формирование списка химии | ||
getChemOutput = function(data, id) | getChemOutput = function(data, id) | ||
if chemCache[id] then return chemCache[id] end | |||
local item = findDataById(data, id) | local item = findDataById(data, id) | ||
if not item or not item.SolutionContainerManager or not item.SolutionContainerManager.solutions then return '' end | if not item or not item.SolutionContainerManager or not item.SolutionContainerManager.solutions then | ||
chemCache[id] = '' | |||
return '' | |||
end | |||
local result = {} | local result = {} | ||
| Строка 241: | Строка 264: | ||
end | end | ||
end | end | ||
chemCache[id] = string.format('<ul class="1">%s</ul>', table.concat(result)) | |||
return chemCache[id] | |||
end | end | ||