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

Нет описания правки
Нет описания правки
Метка: ручная отмена
Строка 1: Строка 1:
local p = {}
local p = {}


-- Функция для загрузки данных исследований из JSON-файла
-- Загрузка данных
local function loadResearchData()
local function loadData(filePath)
     local content = mw.title.new("User:IanComradeBot/Песочница.json"):getContent()
     local page = mw.title.new(filePath)
     if not content or content == "" then
     local content = page and page:getContent()
        error("JSON-файл пуст или отсутствует!")
     return content and mw.text.jsonDecode(content) or nil
     end
    local data = mw.text.jsonDecode(content)
    if not data then
        error("Ошибка парсинга JSON!")
    end
    return data
end
end


Строка 73: Строка 67:
     })
     })


     local dataCache = loadResearchData()
     local dataCache = loadData("User:IanComradeBot/Песочница.json")
 
     if not data or type(data) ~= 'table' then
     if not dataCache or #dataCache == 0 then
         return 'Ошибка: Невозможно загрузить данные из JSON.'
         return cssLink .. '<div style="color:red;">Данные исследований не загружены или пусты.</div>'
     end
     end
 
   
     local discipline = frame.args[1] or ""
     local discipline = frame.args[1] or ""


     if discipline and discipline ~= "" then
     if discipline and discipline ~= "" then
        -- Инициализация строки вывода
         local out = cssLink .. '<div class="research-group">'
         local out = cssLink .. '<div class="research-group">'


Строка 98: Строка 90:


             -- Генерация строк prerequisites и unlocks
             -- Генерация строк prerequisites и unlocks
             local prerequisitesStr = ""
             local prerequisitesStr = generateTemplate(tech.technologyPrerequisites, "prerequisite")
            if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
             local unlocksStr = generateTemplate(tech.recipeUnlocks, "unlock")
                prerequisitesStr = generateTemplate(tech.technologyPrerequisites, "prerequisite")
            end
 
             local unlocksStr = ""
            if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
                unlocksStr = generateTemplate(tech.recipeUnlocks, "unlock")
            end


             -- Формируем вывод с использованием шаблона
             -- Формируем вывод с использованием шаблона
Строка 125: Строка 110:
         end
         end


         out = out .. '</div>' -- Закрываем блок research-group
         out = out .. '</div>'
         return out
         return out
     else
     else