Модуль:Prototypes/Механика/Доступ: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| (не показано 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. | -- Основная функция модуля | ||
-- | function p.main(frame) | ||
local | local param1 = frame.args[1] | ||
if not | |||
-- Режим перевода | |||
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 | ||
if not accessData then | |||
local success, | return "Ошибка: не удалось загрузить данные доступа" | ||
if not success or type( | 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 | |||
if item.id == id and item.AccessReader then | |||
for _, item in ipairs( | local result = {} | ||
if | -- Если присутствует accessGroups, обрабатываем их | ||
-- | if item.AccessReader.accessGroups then | ||
for _, group in ipairs(item.AccessReader.accessGroups) do | |||
table. | 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 | |||
end | end | ||
return p | return p | ||