Модуль:Песочница/Pok: различия между версиями

мНет описания правки
мНет описания правки
Строка 2: Строка 2:
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data")
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data")
local itemSlotsData = mw.loadData("Модуль:IanComradeBot/prototypes/ItemSlots.json/data")
local itemSlotsData = mw.loadData("Модуль:IanComradeBot/prototypes/ItemSlots.json/data")
local chemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/chem.json/data")


local p = {}
local p = {}
Строка 64: Строка 65:
-- Форматирование содержимого
-- Форматирование содержимого
formatContent = function(content)
formatContent = function(content)
     if type(content) == "string" then
     if type(content) == "table" and not content.id then
        local id = content
        local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', id)
        local image = string.format('%s.png', id)
        return string.format(
            '{{LinkСard|SideStyle=1|background-color=#cbcbff0a|image=%s|name=%s}}',
            image, name
        )
    end
 
    if not content.id then
         return "Ошибка: отсутствует id у элемента."
         return "Ошибка: отсутствует id у элемента."
     end
     end


     local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', content.id)
    -- Если передан объект с id
     local image = string.format('%s.png', content.id)
    local id = content.id or content
     local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', id)
     local image = string.format('%s.png', id)
     local amount = (content.amount and content.amount ~= 1) and string.format(" [%d]", content.amount) or ""
     local amount = (content.amount and content.amount ~= 1) and string.format(" [%d]", content.amount) or ""
     local prob = ""
     local prob = ""
Строка 92: Строка 85:


     return string.format(
     return string.format(
         '{{LinkСard|SideStyle=1|background-color=#cbcbff0a|image=%s|name=%s%s%s {{#invoke:Песочница/Pok|main|framing|contained|%s}} {{#invoke:Песочница/Pok|main|framing|slot|%s}} }}',
         '{{LinkСard|SideStyle=1|background-color=#cbcbff0a|image=%s|name=%s%s%s {{#invoke:Песочница/Pok|main|framing|contained|%s}} {{#invoke:Песочница/Pok|main|framing|slot|%s}} {{#invoke:Песочница/Pok|main|framing|chem|%s}} }}',
         image, name, amount, prob, content.id, content.id
         image, name, amount, prob, id, id, id
     )
     )
end
end
Строка 291: Строка 284:
getChemOutput = function(itemData, id)
getChemOutput = function(itemData, id)
     local item = findDataById(itemData, id)
     local item = findDataById(itemData, 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  
        return ''
    end
 
    local foodSolution = item.SolutionContainerManager.solutions["food"]
    if not foodSolution or not foodSolution.reagents then
        return ''
    end


     local result = ""
     local result = ""
     for _, solution in pairs(item.SolutionContainerManager.solutions) do
     for _, reagent in ipairs(foodSolution.reagents) do
        for _, reagent in ipairs(solution.reagents) do
        result = result .. string.format(
            result = result .. string.format('<li>[[Химия#chem_%s|%s]] (%d ед.)</li>', reagent.ReagentId, reagent.ReagentId, reagent.Quantity)
            '<li>[[Химия#chem_%s|%s]] (%d ед.)</li>',
         end
            reagent.ReagentId, reagent.ReagentId, reagent.Quantity
         )
     end
     end
     return string.format('<ul class="1">%s</ul>', result)
     return string.format('<ul class="1">%s</ul>', result)
end
end
Строка 322: Строка 326:


         if subMode == 'chem' then
         if subMode == 'chem' then
             return frame:preprocess('{{СollapsibleMenu|' .. getChemOutput(itemDataIndex, id) .. '}}')
             return frame:preprocess('{{СollapsibleMenu|color=#3e7c82|' .. getChemOutput(chemData, id) .. '}}')
         elseif subMode == 'contained' then
         elseif subMode == 'contained' then
             return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}')
             return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}')
Строка 332: Строка 336:
    if not startingItem then return "" end
    if not startingItem then return "" end
    return frame:preprocess('{{СollapsibleMenu|' .. formatContent(startingItem) .. '}}')
    return frame:preprocess('{{СollapsibleMenu|color=#656426|' .. formatContent(startingItem) .. '}}')
         else
         else
             return 'Неизвестный подрежим для framing: ' .. subMode
             return 'Неизвестный подрежим для framing: ' .. subMode
         end
         end
     elseif mode == 'chem' then
     elseif mode == 'chem' then
         return frame:preprocess(getChemOutput(itemDataIndex, id))
         return frame:preprocess(getChemOutput(chemData, id))
     elseif mode == 'contained' then
     elseif mode == 'contained' then
         return frame:preprocess(getContainedOutput(itemDataIndex, id))
         return frame:preprocess(getContainedOutput(itemDataIndex, id))