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

Отмена правки 71966, сделанной Pok (обсуждение)
Метка: отмена
мНет описания правки
Строка 6: Строка 6:
local itemSlotsData    = mw.loadData("Модуль:IanComradeBot/prototypes/ItemSlots.json/data")
local itemSlotsData    = mw.loadData("Модуль:IanComradeBot/prototypes/ItemSlots.json/data")
local itemStackData    = mw.loadData("Модуль:IanComradeBot/prototypes/fills/stack.json/data")
local itemStackData    = mw.loadData("Модуль:IanComradeBot/prototypes/fills/stack.json/data")
local chemData          = mw.loadData("Модуль:IanComradeBot/prototypes/fills/chem.json/data")
local chemTranslateData = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data")
local chemTranslateData = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data")


Строка 301: Строка 300:
     end
     end


     local allReagents = {}
     -- Функция для загрузки данных из модуля по типу раствора
     for _, solution in pairs(item.SolutionContainerManager.solutions) do
     local function loadSolutionData(solutionType)
         if solution and solution.reagents then
         local modulePath = string.format("Модуль:IanComradeBot/prototypes/fills/chem/%s.json/data", solutionType)
            for _, reagent in ipairs(solution.reagents) do
        return mw.loadData(modulePath)
                table.insert(allReagents, reagent)
            end
        end
     end
     end


     local hasNonFiber = false
     local function processSolution(solutionType)
    for _, reagent in ipairs(allReagents) do
        local solutionModule = loadSolutionData(solutionType)
         if reagent.ReagentId ~= "Fiber" then
         if not solutionModule or not solutionModule[solutionType] then
             hasNonFiber = true
             return ""
            break
         end
         end
    end


    if not hasNonFiber then
         local solution = solutionModule[solutionType]
         return ''
    end
 
    local function processSolution(solution)
         local output = ""
         local output = ""
         if solution and solution.reagents then
         if solution and solution.reagents then
             for _, reagent in ipairs(solution.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
         end
Строка 338: Строка 331:


     local result = ""
     local result = ""
     result = result .. processSolution(item.SolutionContainerManager.solutions["drink"])
     -- Перебираем необходимые типы растворов
     result = result .. processSolution(item.SolutionContainerManager.solutions["food"])
     result = result .. processSolution("drink")
     result = result .. processSolution(item.SolutionContainerManager.solutions["beaker"])
     result = result .. processSolution("beaker")
     result = result .. processSolution(item.SolutionContainerManager.solutions["injector"])
     result = result .. processSolution("injector")
     result = result .. processSolution(item.SolutionContainerManager.solutions["pen"])
     result = result .. processSolution("pen")


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