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

Материал из Space Station 14 Вики
Новая страница: «local p = {} function p.main(frame) local icon = frame.args.itemId or "" local name = frame.args.name or "" local discipline = frame.args.discipline or "" local tier = frame.args.tier or "" local cost = frame.args.cost or "" local recipeUnlocks = frame.args.recipeUnlocks or "" local disciplineIcon = "" local disciplineName = "" if discipline == "Arsenal" then local disciplineIcon = "16px|link=" local disciplineName...»
 
мНет описания правки
 
(не показано 76 промежуточных версий этого же участника)
Строка 1: Строка 1:
-- Загрузка данных
local recipeData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipes.json/data")
local p = {}
local p = {}
-- Функция для загрузки данных исследований из JSON-файла
local function loadResearchData()
    return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/research.json"):getContent())
end
-- Таблица для перевода названий дисциплин
local disciplineMapping = {
    Arsenal = "Арсенал",
    Industrial = "Промышленность",
    Experimental = "Экспериментальное",
    CivilianServices = "Обслуживание персонала"
}
-- Таблица для цветов по уровням
local tierColors = {
    [1] = "#54d554",
    [2] = "#ed9000",
    [3] = "#d72a2a"
}


function p.main(frame)
function p.main(frame)
local icon = frame.args.itemId or ""
    local dataCache = loadResearchData()
local name = frame.args.name or ""
 
local discipline = frame.args.discipline or ""
    -- Получаем ID и иконку из параметров
local tier = frame.args.tier or ""
    local researchId = frame.args[1] or ""
local cost = frame.args.cost or ""
    local icon = frame.args[2] or ""
local recipeUnlocks = frame.args.recipeUnlocks or ""
 
    if researchId and researchId ~= "" then
local disciplineIcon = ""
        local out = ""
local disciplineName = ""
 
        -- Поиск исследования по ID
if discipline == "Arsenal" then
        local tech = nil
local disciplineIcon = "[[Файл:Arsenal.png|16px|link=]]"
        for _, research in ipairs(dataCache) do
local disciplineName = "Арсенал"
            if research and research.id == researchId then
elseif discipline == "Industrial" then
                tech = research
local disciplineIcon = "[[Файл:Industrial.png|16px|link=]]"
                break
local disciplineName = "Промышленность"
            end
elseif discipline == "Experimental" then
        end
local disciplineIcon = "[[Файл:Experimental.png|16px|link=]]"
 
local disciplineName = "Экспериментальное"
        if not tech then
elseif discipline == "CivilianServices" then
            out = out .. '<div style="color:red;">Исследование с ID "' .. researchId .. '" не найдено.</div>'
local disciplineIcon = "[[Файл:CivilianServices.png|16px|link=]]"
        else
local disciplineName = "Обслуживание персонала"
            local tierColor = tierColors[tech.tier] or "#FFFFFF"
end
            local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
            local iconPath = icon ~= "" and icon or (tech.icon and tech.icon.sprite or nil)
out = out .. '<div class="research" id=" '.. discipline ..' ">'
 
out = out .. '<div class="research__images">[[Файл: ' .. icon .. ' .png|64px|центр|link=]]</div>'
            -- Формирование строки необходимых исследований
out = out .. '<div class="research__name"> ' .. name .. ' ' .. disciplineIcon .. ' </div>'
            local prerequisites = ""
out = out .. '<div class="research__type">'
            if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
out = out .. '<div>Уровень: ' .. tier .. ' ,</div>'
                prerequisites = '<ul>'
out = out .. '<div class="research__category"> ' .. disciplineName .. ' </div>'
                for _, prerequisiteId in ipairs(tech.technologyPrerequisites) do
out = out .. '<div>Стоимость: <span style="color:#DA70D6;"> ' .. cost .. ' </span></div>'
                    if prerequisiteId and prerequisiteId ~= "" then
out = out .. '</div>'
                        -- Находим название исследования по ID
out = out .. '<div class="research__unblocks">Разблокирует:'
                        local prerequisiteName = ""
out = out .. '<ul>'
                        for _, research in ipairs(dataCache) do
out = out .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл: ' .. recipeUnlocks .. ' .png| ' .. recipeUnlocks .. ' |Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname| ' .. recipeUnlocks .. ' }}</li>'
                            if research and research.id == prerequisiteId then
out = out .. '</ul>'
                                prerequisiteName = research.name
out = out .. '</div>'
                                break
out = out .. '</div>'
                            end
                        end
 
                        -- Если название найдено, выводим его
                        if prerequisiteName ~= "" then
                            prerequisites = prerequisites .. '<li>{{#invoke:Ftl|main|translation|'.. prerequisiteName .. '}}</li>'
                        end
                    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
            }
 
            -- Добавление prerequisites только если он существует
            if prerequisites ~= "" then
                templateArgs.prerequisites = prerequisites
            end


return out
            out = out .. frame:expandTemplate({
                title = 'Prototypes/Механика/Исследование',
                args = templateArgs
            })
end
        return mw.getCurrentFrame():preprocess(out)
    else
        return '<div style="color:red;">Не указан ID исследования.</div>'
    end
end
end


return p
return p

Текущая версия от 14:40, 13 февраля 2025

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

-- Загрузка данных
local recipeData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipes.json/data")

local p = {}

-- Функция для загрузки данных исследований из JSON-файла
local function loadResearchData()
    return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/prototypes/research.json"):getContent())
end

-- Таблица для перевода названий дисциплин
local disciplineMapping = {
    Arsenal = "Арсенал",
    Industrial = "Промышленность",
    Experimental = "Экспериментальное",
    CivilianServices = "Обслуживание персонала"
}

-- Таблица для цветов по уровням
local tierColors = {
    [1] = "#54d554",
    [2] = "#ed9000",
    [3] = "#d72a2a"
}

function p.main(frame)
    local dataCache = loadResearchData()

    -- Получаем 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

        if not tech then
            out = out .. '<div style="color:red;">Исследование с ID "' .. researchId .. '" не найдено.</div>'
        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)

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

                        -- Если название найдено, выводим его
                        if prerequisiteName ~= "" then
                            prerequisites = prerequisites .. '<li>{{#invoke:Ftl|main|translation|'.. prerequisiteName .. '}}</li>'
                        end
                    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
            }

            -- Добавление prerequisites только если он существует
            if prerequisites ~= "" then
                templateArgs.prerequisites = prerequisites
            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 p