Модуль:Prototypes/Механика/Доступ: различия между версиями

мНет описания правки
мНет описания правки
 
(не показано 13 промежуточных версий этого же участника)
Строка 1: Строка 1:
-- Загрузка данных
local accessData = mw.loadData("Модуль:IanComradeBot/prototypes/AccessReader/access.json/data")
local p = {}
local p = {}


-- Таблица для перевода слов
-- Таблица для перевода слов
local translations = {
local translations = {
    ["Command"] = "Командование",
    ["Captain"] = "Капитан",
    ["HeadOfPersonnel"] = "Глава персонала",
    ["Cryogenics"] = "Криогеника",
    ["HeadOfSecurity"] = "Глава службы безопасности",
    ["Security"] = "Служба безопасности",
    ["Armory"] = "Оружейная",
    ["Brig"] = "Бриг",
    ["Detective"] = "Детектив",
    ["ChiefEngineer"] = "Старший инженер",
    ["Engineering"] = "Инженерный",
    ["Atmospherics"] = "Атмосферный",
    ["ResearchDirector"] = "Научный руководитель",
    ["Research"] = "Научный",
    ["ChiefMedicalOfficer"] = "Главный врач",
    ["Medical"] = "Медицинский",
    ["Chemistry"] = "Химия",
    ["Paramedic"] = "Парамедик",
    ["Quartermaster"] = "Квартирмейстер",
    ["Cargo"] = "Снабжение",
    ["Salvage"] = "Утилизаторский",
    ["Bar"] = "Бар",
     ["Kitchen"] = "Кухня",
     ["Kitchen"] = "Кухня",
     ["Theatre"] = "Театр"
    ["Hydroponics"] = "Гидропоника",
    ["Service"] = "Сервис",
    ["Janitor"] = "Уборщик",
     ["Theatre"] = "Театр",
    ["Chapel"] = "Церковь",
    ["Lawyer"] = "Юридический",
    ["Maintenance"] = "Техобслуживание",
    ["External"] = "Внешний",
    ["NuclearOperative"] = "Ядерный оперативник",
    ["SyndicateAgent"] = "Агент Синдиката",
    ["CentralCommand"] = "Центральное командование",
    ["Wizard"] = "Волшебник",
    ["AllAccess"] = "Полный доступ"
}
}


function p.parse(frame)
-- Основная функция модуля
     -- Получение входных данных
function p.main(frame)
     local input = frame.args[1]
    local param1 = frame.args[1]
     if not input then
   
     -- Режим перевода
     if param1 == "translate" then
        local key = frame.args[2]
        if not key then
            return "Ошибка: отсутствует ключ для перевода"
        end
        return translations[key] or key
    end
 
    local id = param1
     if not id then
         return "Нет данных для обработки"
         return "Нет данных для обработки"
     end
     end
 
   
     -- Преобразование строки в таблицу Lua
    if not accessData then
     local success, data = pcall(mw.text.jsonDecode, input)
        return "Ошибка: не удалось загрузить данные доступа"
     if not success or type(data) ~= "table" then
    end
         return "Ошибка: некорректный формат входных данных"
      
     local success, jsonData = pcall(function() return accessData end)
     if not success or type(jsonData) ~= "table" then
         return "Ошибка: некорректный формат данных доступа"
     end
     end


    -- Список для хранения переведённых значений
     for _, item in ipairs(jsonData) do
    local result = {}
         if item.id == id and item.AccessReader then
     for _, item in ipairs(data) do
            local result = {}
         if type(item) == "table" and item[1] then
             -- Если присутствует accessGroups, обрабатываем их
             -- Замена ID доступов на их название
             if item.AccessReader.accessGroups then
             local translated = translations[item[1]] or item[1]
                for _, group in ipairs(item.AccessReader.accessGroups) do
             table.insert(result, translated)
                    for _, access in ipairs(group) do
                        table.insert(result, translations[access] or access)
                    end
                end
            -- Если accessGroups отсутствует, используем access
            elseif item.AccessReader.access then
                for _, accessList in ipairs(item.AccessReader.access) do
                    for _, access in ipairs(accessList) do
                        table.insert(result, translations[access] or access)
                    end
                end
            end
             if #result > 0 then
                return table.concat(result, ", ")
            end
         end
         end
     end
     end
 
      
     -- Объединение переведённых элементов через запятую
     return ""
     return table.concat(result, ", ")
end
end


return p
return p