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

мНет описания правки
Нет описания правки
Строка 47: Строка 47:
     return nil
     return nil
end
end
-- Локальные функции
local findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector


-- Поиск данных по ID через индекс
-- Поиск данных по ID через индекс
local function findDataById(itemDataIndex, id)
findDataById = function(itemDataIndex, id)
     if not itemDataIndex then return nil end
     if not itemDataIndex then return nil end
    for _, item in ipairs(itemDataIndex) do
for _, item in ipairs(itemDataIndex) do
        if item.id == id then
if item.id == id then
            return item
return item
        end
end
    end
end
end
end
-- Локальные функции
local formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector


-- Форматирование содержимого
-- Форматирование содержимого
formatContent = function(content)
formatContent = function(content)
     local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', content.id or content)
    if type(content) == "table" and not content.id then
     local image = string.format('%s.png', content.id or content)
        return "Ошибка: отсутствует id у элемента."
local amount = (content.amount and content.amount ~= 1) and string.format(" [%d]", content.amount) or ""
    end
 
    -- Если передан объект с 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 prob = ""
     local prob = ""


Строка 78: Строка 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}} }}',
         image, name, amount, prob, (content.id or ""), content
         image, name, amount, prob, id, id
     )
     )
end
end
Строка 310: Строка 317:
         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
elseif mode == "slot" then
        local itemDataEntry = findDataById(itemSlotsData, id)
    local itemDataEntry = findDataById(itemSlotsData, id)
        if not itemDataEntry then return "ID не найден в данных ItemSlots." end
    if not itemDataEntry then return "ID не найден в данных ItemSlots." end
        local startingItem = getFirstStartingItem(itemDataEntry)
    local startingItem = getFirstStartingItem(itemDataEntry)
        if not startingItem then return "Не найден startingItem в slots." end
    if not startingItem then return "Не найден startingItem в slots." end
        return frame:preprocess('{{СollapsibleMenu|' .. formatContent(startingItem)) .. '}}'
    return frame:preprocess(formatContent(startingItem))
         else
         else
             return 'Неизвестный подрежим для framing: ' .. subMode
             return 'Неизвестный подрежим для framing: ' .. subMode
Строка 325: Строка 332:
     elseif mode == 'contained' then
     elseif mode == 'contained' then
         return frame:preprocess(getContainedOutput(itemDataIndex, id))
         return frame:preprocess(getContainedOutput(itemDataIndex, id))
    elseif mode == "slot" then
elseif mode == "slot" then
        local itemDataEntry = findDataById(itemSlotsData, id)
    local itemDataEntry = findDataById(itemSlotsData, id)
        if not itemDataEntry then return "ID не найден в данных ItemSlots." end
    if not itemDataEntry then return "ID не найден в данных ItemSlots." end
 
        local startingItem = getFirstStartingItem(itemDataEntry)
    local startingItem = getFirstStartingItem(itemDataEntry)
        if not startingItem then return "Не найден startingItem в slots." end
    if not startingItem then return "Не найден startingItem в slots." end
 
        return frame:preprocess(formatContent(startingItem))
    return frame:preprocess(formatContent(startingItem))
     elseif mode == 'rolls' then
     elseif mode == 'rolls' then
         local entity = findDataById(itemDataIndex, id)
         local entity = findDataById(itemDataIndex, id)