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

мНет описания правки
Нет описания правки
Метка: ручная отмена
Строка 1: Строка 1:
-- Загрузка данных
-- Загрузка данных
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 p = {}
local p = {}
Строка 32: Строка 31:
     return result
     return result
end
end
-- Функция для поиска первого startingItem в slots
local function getFirstStartingItem(data)
    if not data or not data.ItemSlots or not data.ItemSlots.slots then
        return nil
    end
   
    for _, slot in pairs(data.ItemSlots.slots) do
        if slot.startingItem and slot.startingItem ~= "" then
            return slot.startingItem
        end
    end
   
    return nil
end


-- Локальные функции
-- Локальные функции
Строка 64: Строка 47:
-- Форматирование содержимого
-- Форматирование содержимого
formatContent = function(content)
formatContent = function(content)
     if type(content) == "table" and not content.id then
     if not content.id then
         return "Ошибка: отсутствует id у элемента."
         return "Ошибка: отсутствует id у элемента."
     end
     end


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


Строка 84: Строка 65:


     return string.format(
     return string.format(
         '{{LinkСard|SideStyle=1|background-color=#cbcbff0a|image=%s|name=%s%s%s {{#invoke:Prototypes/Хранилище/Предмет|main|framing|contained|%s}} {{#invoke:Prototypes/Хранилище/Предмет|main|framing|slot|%s}} }}',
         '{{LinkСard|SideStyle=1|background-color=#cbcbff0a|image=%s|name=%s%s%s {{#invoke:Prototypes/Хранилище/Предмет|main|framing|contained|%s}} }}',
         image, name, amount, prob, id, id
         image, name, amount, prob, content.id
     )
     )
end
end
Строка 317: Строка 298:
         elseif subMode == 'contained' then
         elseif subMode == 'contained' then
             return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}')
             return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}')
elseif subMode == "slot" then
    local itemDataEntry = findDataById(itemSlotsData, id)
    if not itemDataEntry then return "" end
    local startingItem = getFirstStartingItem(itemDataEntry)
    if not startingItem then return "" end
    return frame:preprocess('{{СollapsibleMenu|color=#655e59|' .. formatContent(startingItem) .. '}}')
         else
         else
             return 'Неизвестный подрежим для framing: ' .. subMode
             return 'Неизвестный подрежим для framing: ' .. subMode
Строка 332: Строка 305:
     elseif mode == 'contained' then
     elseif mode == 'contained' then
         return frame:preprocess(getContainedOutput(itemDataIndex, id))
         return frame:preprocess(getContainedOutput(itemDataIndex, id))
elseif mode == "slot" then
    local itemDataEntry = findDataById(itemSlotsData, id)
    if not itemDataEntry then return "" end
    local startingItem = getFirstStartingItem(itemDataEntry)
    if not startingItem then return "" end
    return frame:preprocess(formatContent(startingItem))
     elseif mode == 'rolls' then
     elseif mode == 'rolls' then
         local entity = findDataById(itemDataIndex, id)
         local entity = findDataById(itemDataIndex, id)