Модуль:Research

Материал из Space Station 14 Вики

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

local p = {}

-- Функция для загрузки JSON-данных
local function loadJsonData()
    local title = mw.title.new('Участник:IanComradeBot/research prototypes.json')
    local jsonData = title:getContent() or "{}"  
    return mw.ext.json:decode(jsonData)  
end

function p.main(frame)
    -- Подключение CSS файла
    local cssLink = frame:extensionTag('templatestyles', '', {
        src = 'Шаблон:Research/styles.css'
    })

    local discipline = frame.args.discipline or ""
    local data = loadJsonData()  -- Загружаем JSON-данные
    local out = cssLink

    -- Фильтрация данных по дисциплине
    for tier, items in pairs(data) do
        for _, item in ipairs(items) do
            if item.discipline == discipline then
                local icon = item.icon or ""
                local name = item.name or ""
                local tier = item.tier or ""
                local cost = item.cost or ""
                local recipeUnlocks = item.recipeUnlocks or {}

                local disciplineName = ""
                if discipline == "Arsenal" then
                    disciplineName = "Арсенал"
                elseif discipline == "Industrial" then
                    disciplineName = "Промышленность"
                elseif discipline == "Experimental" then
                    disciplineName = "Экспериментальное"
                elseif discipline == "CivilianServices" then
                    disciplineName = "Обслуживание персонала"
                end

                -- Формирование HTML
                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 .. '[[Файл:' .. 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

    return out
end

return p