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

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


-- Функция для загрузки JSON-данных
-- Функция для загрузки данных исследований из JSON-файла
local function loadJsonData()
local function loadResearchData()
     local jsonData = mw.title.new('User:IanComradeBot/research prototypes.json'):getContent()
     return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/research.json"):getContent())
    return mw.text.json.decode(jsonData)
end
end
-- Таблица для перевода названий дисциплин
local disciplineMapping = {
    Arsenal = "Арсенал",
    Industrial = "Промышленность",
    Experimental = "Экспериментальное",
    CivilianServices = "Обслуживание персонала"
}
-- Таблица для цветов по уровням
local tierColors = {
    [1] = "#54d554",
    [2] = "#ed9000",
    [3] = "#d72a2a"
}


function p.main(frame)
function p.main(frame)
     -- Подключение CSS файла
    local dataCache = loadResearchData()
     local cssLink = frame:extensionTag('templatestyles', '', {
 
        src = 'Шаблон:Research/styles.css'
     -- Получаем ID и иконку из параметров
     })
     local researchId = frame.args[1] or ""
    local icon = frame.args[2] or ""
 
     if researchId and researchId ~= "" then
        local out = ""
 
        -- Поиск исследования по ID
        local tech = nil
        for _, research in ipairs(dataCache) do
            if research and research.id == researchId then
                tech = research
                break
            end
        end


    local discipline = frame.args.discipline or ""
        if not tech then
    local data = loadJsonData() -- JSON-данные
            out = out .. '<div style="color:red;">Исследование с ID "' .. researchId .. '" не найдено.</div>'
    local out = cssLink
        else
            local tierColor = tierColors[tech.tier] or "#FFFFFF"
            local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
            local iconPath = icon ~= "" and icon or (tech.icon and tech.icon.sprite or nil)


    -- Фильтрация данных по дисциплине
            -- Формирование строки необходимых исследований
    for tier, items in pairs(data) do
            local prerequisites = ""
        for _, item in ipairs(items) do
            if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
            if item.discipline == discipline then
                prerequisites = '<ul>'
                local icon = item.icon or ""
                for _, prerequisiteId in ipairs(tech.technologyPrerequisites) do
                local name = item.name or ""
                    if prerequisiteId and prerequisiteId ~= "" then
                local tier = item.tier or ""
                        -- Находим название исследования по ID
                local cost = item.cost or ""
                        local prerequisiteName = ""
                local recipeUnlocks = item.recipeUnlocks or ""
                        for _, research in ipairs(dataCache) do
                            if research and research.id == prerequisiteId then
                                prerequisiteName = research.name
                                break
                            end
                        end


                local disciplineName = ""
                        -- Если название найдено, выводим его
                if discipline == "Arsenal" then
                        if prerequisiteName ~= "" then
                    disciplineName = "Арсенал"
                            prerequisites = prerequisites .. '<li>{{#invoke:Ftl|main|translation|'.. prerequisiteName .. '}}</li>'
                elseif discipline == "Industrial" then
                        end
                     disciplineName = "Промышленность"
                     end
                elseif discipline == "Experimental" then
                    disciplineName = "Экспериментальное"
                elseif discipline == "CivilianServices" then
                    disciplineName = "Обслуживание персонала"
                 end
                 end
                prerequisites = prerequisites .. '</ul>'
            end
            -- Формирование строки открываемых исследований
local unlocks = ""
if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
    unlocks = '<ul>'
    for _, recipeId in ipairs(tech.recipeUnlocks) do
        if recipeId and recipeId ~= "" then
            -- Ищем в recipeData объект с id == recipeId
            local newId = recipeId
            for _, rec in ipairs(recipeData) do
                if rec and rec.id == recipeId then
                    newId = rec.result or recipeId
                    break
                end
            end
            unlocks = unlocks .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
                .. newId .. '.png|' .. newId
                .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|'
                .. newId .. '}}</li>'
        end
    end
    unlocks = unlocks .. '</ul>'
end
            -- Шаблон для отображения блока исследования
            local templateArgs = {
                id = tech.id,
                icon = iconPath,
                name = tech.name,
                discipline = tech.discipline,
                tier = tech.tier,
                tierColor = tierColor,
                disciplineName = disciplineName,
                cost = tech.cost,
                unlocks = unlocks
            }


                -- Формирование HTML
            -- Добавление prerequisites только если он существует
                out = out .. '<div class="research" id="'.. discipline ..'">'
            if prerequisites ~= "" then
                 out = out .. '<div class="research__images">[[Файл:' .. icon .. '.png|64px|центр|link=]]</div>'
                 templateArgs.prerequisites = prerequisites
                out = out .. '<div class="research__name">' .. name .. '[[Файл:' .. discipline .. '.png|16px|link=]]</div>'
                out = out .. '<div class="research__type">'
                out = out .. '<div>Уровень:  ' .. tier .. ' ,</div>'
                out = out .. '<div class="research__category">' .. disciplineName .. '</div>'
                out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. cost .. '</span></div>'
                out = out .. '</div>'
                out = out .. '<div class="research__unblocks">Разблокирует:'
                out = out .. '<ul>'
                for _, recipe in ipairs(recipeUnlocks) do
                    out = out .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' .. recipe .. '.png|' .. recipe .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' .. recipe .. '}}</li>'
                end
                out = out .. '</ul>'
                out = out .. '</div>'
                out = out .. '</div>'
             end
             end
         end
 
            out = out .. frame:expandTemplate({
                title = 'Prototypes/Механика/Исследование',
                args = templateArgs
            })
end
         return mw.getCurrentFrame():preprocess(out)
    else
        return '<div style="color:red;">Не указан ID исследования.</div>'
     end
     end
    return out
end
end


return p
return p