Модуль:Entity Tags

Материал из Adventure Station

Для документации этого модуля может быть создана страница Модуль:Entity Tags/doc

-- Загрузка данных
local tagsData = mw.loadData("Модуль:WikiBotADT/prototypes/entity tags.json/data")

local p = {}

-- Основная функция модуля
function p.main(frame)
    local args = frame.args
    local mode = args[1] or ""
    local searchParam = args[2] or ""
    
    if searchParam == "" then
        return "Ошибка: не указан параметр поиска."
    end
    
    -- Поиск id по тегам
    if mode == "id" then
        for _, entry in ipairs(tagsData) do
            if entry.id == searchParam then
                if entry.Tag and type(entry.Tag.tags) == "table" then
                    local tagList = {}
                    for _, tag in ipairs(entry.Tag.tags) do
                        table.insert(tagList, tag)
                    end
                    return table.concat(tagList, ", ")
                else
                    return ""
                end
            end
        end
        return ""

    -- Поиск тегов по id
    elseif mode == "tag" then
        local foundIds = {}
        for _, entry in ipairs(tagsData) do
            if entry.Tag and type(entry.Tag.tags) == "table" then
                for _, tag in ipairs(entry.Tag.tags) do
                    if tag == searchParam then
                        table.insert(foundIds, entry.id)
                        break
                    end
                end
            end
        end
        
        if #foundIds > 0 then
            return "Найденные ID: " .. table.concat(foundIds, ", ")
        else
            return "Нет записей с тегом " .. searchParam .. "."
        end
        
    else
        return "Ошибка: неизвестный режим " .. mode .. ". Используйте id или tag."
    end
end

return p