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

мНет описания правки
Метка: ручная отмена
Нет описания правки
Метка: ручная отмена
Строка 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
        -- Если указан range
         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
        -- Если указано value
         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
     return table.concat(result)
      
    processRollsCache[rolls] = table.concat(result)
    return processRollsCache[rolls]
end
end


Строка 85: Строка 91:
     local result = {}
     local result = {}
     for _, content in ipairs(contents) do
     for _, content in ipairs(contents) do
         result[#result + 1] = formatContent(content)
         result[#result + 1] = tostring(formatContent(content))
     end
     end
     return table.concat(result)
      
    local cacheKey = table.concat(result, ",")
    if containedCache[cacheKey] then return containedCache[cacheKey] 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 return 'Таблица не найдена.' end
     if not tableData then  
        tableCache[tableId] = 'Таблица не найдена.'
        return tableCache[tableId]
    end


     if tableData['!type:GroupSelector'] then
     if tableData['!type:GroupSelector'] then
         return handleGroupSelector(tableData['!type:GroupSelector'])
         tableCache[tableId] = handleGroupSelector(tableData['!type:GroupSelector'])
     elseif tableData['!type:AllSelector'] then
     elseif tableData['!type:AllSelector'] then
         return processNestedSelectors(tableData['!type:AllSelector'].children)
         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
     return string.format('<ul class="1">%s</ul>', table.concat(result))
      
    chemCache[id] = string.format('<ul class="1">%s</ul>', table.concat(result))
    return chemCache[id]
end
end