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

Нет описания правки
Метка: ручная отмена
Отмена правки 64370, сделанной 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
        -- Если указан 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)
Строка 23: Строка 18:
         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


Строка 91: Строка 85:
     local result = {}
     local result = {}
     for _, content in ipairs(contents) do
     for _, content in ipairs(contents) do
         result[#result + 1] = tostring(formatContent(content))
         result[#result + 1] = 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


Строка 127: Строка 116:
-- Обработка таблиц
-- Обработка таблиц
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 return 'Таблица не найдена.' end
        tableCache[tableId] = 'Таблица не найдена.'
        return tableCache[tableId]
    end


     if tableData['!type:GroupSelector'] then
     if tableData['!type:GroupSelector'] then
         tableCache[tableId] = handleGroupSelector(tableData['!type:GroupSelector'])
         return handleGroupSelector(tableData['!type:GroupSelector'])
     elseif tableData['!type:AllSelector'] then
     elseif tableData['!type:AllSelector'] then
         tableCache[tableId] = processNestedSelectors(tableData['!type:AllSelector'].children)
         return processNestedSelectors(tableData['!type:AllSelector'].children)
    else
        tableCache[tableId] = 'Таблица не содержит элементов.'
     end
     end
   
 
     return tableCache[tableId]
     return 'Таблица не содержит элементов.'
end
end


Строка 250: Строка 232:
-- Формирование списка химии
-- Формирование списка химии
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  
     if not item or not item.SolutionContainerManager or not item.SolutionContainerManager.solutions then return '' end
        chemCache[id] = ''
        return ''  
    end


     local result = {}
     local result = {}
Строка 264: Строка 241:
         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