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

мНет описания правки
мНет описания правки
Строка 292: Строка 292:
---------------------------------------------------------------------
---------------------------------------------------------------------
-- Формирование списка химии
-- Формирование списка химии
getChemOutput = function(itemData, id)
getChemOutput = function(id)
    local item = findDataById(itemData, id)
    if not item
      or not item.SolutionContainerManager
      or not item.SolutionContainerManager.solutions then
        return ''
    end
 
    -- Функция для загрузки данных из модуля по типу раствора
     local function loadSolutionData(solutionType)
     local function loadSolutionData(solutionType)
         local modulePath = string.format("Модуль:IanComradeBot/prototypes/fills/chem/%s.json/data", solutionType)
         local modulePath = string.format("Модуль:IanComradeBot/prototypes/fills/chem/%s.json/data", solutionType)
Строка 308: Строка 300:
     local function processSolution(solutionType)
     local function processSolution(solutionType)
         local solutionModule = loadSolutionData(solutionType)
         local solutionModule = loadSolutionData(solutionType)
         if not solutionModule or not solutionModule[solutionType] then
         if not solutionModule then
            return ""
        end
 
        local item = findDataById(solutionModule, id)
        if not item then
            return ""
        end
 
        local solutionData = item[solutionType] or item
        if not solutionData or not solutionData.reagents then
             return ""
             return ""
         end
         end


        local solution = solutionModule[solutionType]
         local output = ""
         local output = ""
         if solution and solution.reagents then
         for _, reagent in ipairs(solutionData.reagents) do
            for _, reagent in ipairs(solution.reagents) do
            local chemInfo = chemTranslateData[reagent.ReagentId]
                -- Проверка, чтобы не выводить "Волокно"
            local displayName = chemInfo and chemInfo.name or reagent.ReagentId
                if reagent.ReagentId ~= "Fiber" then
            output = output .. string.format(
                    local chemInfo = chemTranslateData[reagent.ReagentId]
                '<li>[[Химия#chem_%s|%s]] (%d ед.)</li>',
                    local displayName = chemInfo and chemInfo.name or reagent.ReagentId
                reagent.ReagentId, displayName, reagent.Quantity
                    output = output .. string.format(
            )
                        '<li>[[Химия#chem_%s|%s]] (%d ед.)</li>',
                        reagent.ReagentId, displayName, reagent.Quantity
                    )
                end
            end
         end
         end
         return output
         return output
Строка 331: Строка 327:


     local result = ""
     local result = ""
     -- Перебираем необходимые типы растворов
     local solutionTypes = {"drink", "beaker", "injector", "pen"}
    result = result .. processSolution("drink")
     for _, solutionType in ipairs(solutionTypes) do
    result = result .. processSolution("beaker")
        result = result .. processSolution(solutionType)
     result = result .. processSolution("injector")
    end
    result = result .. processSolution("pen")


     return result ~= "" and string.format('<ul>%s</ul>', result) or ''
     return result ~= "" and string.format('<ul><b>%s</b></ul>', result) or ''
end
end


Строка 358: Строка 353:
     local id = frame.args[2]
     local id = frame.args[2]


     if not id then return 'Не указан ID.' end
     if not id then  
        return 'Не указан ID.'  
    end
      
      
     local itemDataIndex = itemData
     local itemDataIndex = itemData
      
      
     if not itemData then return 'Не удалось загрузить данные.' end
     if not itemData then  
        return 'Не удалось загрузить данные.'  
    end


     if mode == 'framing' then
     if mode == 'framing' then
Строка 373: Строка 372:


         if subMode == 'chem' then
         if subMode == 'chem' then
             return frame:preprocess('{{СollapsibleMenu|color=#3e7c82|' .. getChemOutput(chemData, id) .. '}}')
             return frame:preprocess('{{СollapsibleMenu|color=#3e7c82|' .. getChemOutput(id) .. '}}')
         elseif subMode == 'contained' then
         elseif subMode == 'contained' then
             return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}')
             return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}')
Строка 400: Строка 399:
         return count or ""
         return count or ""
     elseif mode == 'chem' then
     elseif mode == 'chem' then
         return getChemOutput(chemData, id)
         return getChemOutput(id)
     elseif mode == 'contained' then
     elseif mode == 'contained' then
         return frame:preprocess(getContainedOutput(itemDataIndex, id))
         return frame:preprocess(getContainedOutput(itemDataIndex, id))
Строка 419: Строка 418:
     elseif mode == 'rolls' then
     elseif mode == 'rolls' then
         local entity = findDataById(itemDataIndex, id)
         local entity = findDataById(itemDataIndex, 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