Модуль:Research: различия между версиями

Материал из Space Station 14 Вики
мНет описания правки
Нет описания правки
(не показано 8 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}


-- Функция для загрузки JSON-данных
function p.main(frame)
local function loadJsonData()
-- Подключение CSS файла
    local title = mw.title.new('Участник:IanComradeBot/research prototypes.json')
local cssLink = frame:extensionTag('templatestyles', '', {
    local jsonData = title:getContent() or "{}
src = 'Шаблон:Research/styles.css'
    return mw.ext.json:decode(jsonData)
})
end


function p.main(frame)
local discipline = frame.args.discipline or ""
    -- Подключение CSS файла
 
    local cssLink = frame:extensionTag('templatestyles', '', {
-- Названия технологий
        src = 'Шаблон:Research/styles.css'
local disciplineName = ""
    })
if discipline == "Arsenal" then
disciplineName = "Арсенал"
elseif discipline == "Industrial" then
disciplineName = "Промышленность"
elseif discipline == "Experimental" then
disciplineName = "Экспериментальное"
elseif discipline == "CivilianServices" then
disciplineName = "Обслуживание персонала"
end


    local discipline = frame.args.discipline or ""
-- Загрузка данных из JSON
    local data = loadJsonData() -- Загружаем JSON-данные
local data = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/research prototypes.json"):getContent())
    local out = cssLink


    -- Фильтрация данных по дисциплине
local out = cssLink
    for tier, items in pairs(data) do
local found = false  -- Флаг для отслеживания наличия элементов
        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
if data[discipline] then  -- Проверяем, существует ли ключ для discipline
                    disciplineName = "Арсенал"
for _, tech in ipairs(data[discipline]) do
                elseif discipline == "Industrial" then
found = true
                    disciplineName = "Промышленность"
-- Формирование HTML для каждой технологии
                elseif discipline == "Experimental" then
out = out .. '<div class="research" id="' .. discipline .. '">'
                    disciplineName = "Экспериментальное"
out = out .. '<div class="research__images">[[Файл:' .. tech.icon .. '.png|64px|центр|link=]]</div>'
                elseif discipline == "CivilianServices" then
out = out .. '<div class="research__name">' .. tech.name .. '[[Файл:' .. discipline .. '.png|16px|link=]]</div>'
                    disciplineName = "Обслуживание персонала"
out = out .. '<div class="research__type">'
                end
out = out .. '<div>Уровень:  ' .. tech.tier .. ' ,</div>'
out = out .. '<div class="research__technology">' .. disciplineName .. '</div>'
out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.cost .. '</span></div>'
out = out .. '</div>'
out = out .. '<div class="research__unblocks">Разблокирует:'
out = out .. '<ul>'
for _, recipe in ipairs(tech.recipeUnlocks) do
out = out .. frame:preprocess('<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


                -- Формирование HTML
if not found then
                out = out .. '<div class="research" id="'.. discipline ..'">'
out = out .. '<div>Нет доступных технологий.</div>'
                out = out .. '<div class="research__images">[[Файл:' .. icon .. '.png|64px|центр|link=]]</div>'
end
                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
return out
end
end


return p
return p

Версия от 16:02, 6 октября 2024

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

local p = {}

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

	local discipline = frame.args.discipline or ""

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

	-- Загрузка данных из JSON
	local data = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/research prototypes.json"):getContent())

	local out = cssLink
	local found = false  -- Флаг для отслеживания наличия элементов

	-- Обработка данных
	if data[discipline] then  -- Проверяем, существует ли ключ для discipline
		for _, tech in ipairs(data[discipline]) do
			found = true
			-- Формирование HTML для каждой технологии
			out = out .. '<div class="research" id="' .. discipline .. '">'
			out = out .. '<div class="research__images">[[Файл:' .. tech.icon .. '.png|64px|центр|link=]]</div>'
			out = out .. '<div class="research__name">' .. tech.name .. '[[Файл:' .. discipline .. '.png|16px|link=]]</div>'
			out = out .. '<div class="research__type">'
			out = out .. '<div>Уровень:  ' .. tech.tier .. ' ,</div>'
			out = out .. '<div class="research__technology">' .. disciplineName .. '</div>'
			out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.cost .. '</span></div>'
			out = out .. '</div>'
			out = out .. '<div class="research__unblocks">Разблокирует:'
			out = out .. '<ul>'
			for _, recipe in ipairs(tech.recipeUnlocks) do
				out = out .. frame:preprocess('<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

	if not found then
		out = out .. '<div>Нет доступных технологий.</div>'
	end

	return out
end

return p