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

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


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


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


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


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


                -- Формирование HTML
-- Формирование HTML
                out = out .. '<div class="research" id="'.. discipline ..'">'
out = out .. '<div class="research" id="' .. discipline .. '">'
                out = out .. '<div class="research__images">[[Файл:' .. icon .. '.png|64px|центр|link=]]</div>'
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__name">' .. name .. '[[Файл:' .. discipline .. '.png|16px|link=]]</div>'
                out = out .. '<div class="research__type">'
out = out .. '<div class="research__type">'
                out = out .. '<div>Уровень:  ' .. tier .. ' ,</div>'
out = out .. '<div>Уровень:  ' .. tier .. ' ,</div>'
                out = out .. '<div class="research__category">' .. disciplineName .. '</div>'
out = out .. '<div class="research__category">' .. disciplineName .. '</div>'
                out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. cost .. '</span></div>'
out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. cost .. '</span></div>'
                out = out .. '</div>'
out = out .. '</div>'
                out = out .. '<div class="research__unblocks">Разблокирует:'
out = out .. '<div class="research__unblocks">Разблокирует:'
                out = out .. '<ul>'
out = out .. '<ul>'
                for _, recipe in ipairs(recipeUnlocks) do
for _, recipe in ipairs(recipeUnlocks) do
                    out = out .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' .. recipe .. '.png|' .. recipe .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' .. recipe .. '}}</li>'
out = out .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' .. recipe .. '.png|' .. recipe .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' .. recipe .. '}}</li>'
                end
end
                out = out .. '</ul>'
out = out .. '</ul>'
                out = out .. '</div>'
out = out .. '</div>'
                out = out .. '</div>'
out = out .. '</div>'
            end
end
        end
end
    end


    return out
return out
end
end


return p
return p