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

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
 
(не показано 9 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}
-- Функция для загрузки JSON-данных
local function loadJsonData()
local jsonData = mw.title.new('User:IanComradeBot/research prototypes.json'):getContent() or "{}"
return mw.text.jsonDecode(jsonData)
end


function p.main(frame)
function p.main(frame)
Строка 14: Строка 8:


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


-- Фильтрация данных по дисциплине
-- Названия технологий
for _, item in ipairs(data) do
local disciplineName = ""
if item.discipline == discipline then
if discipline == "Arsenal" then
local icon = item.icon or ""
disciplineName = "Арсенал"
local name = item.name or ""
elseif discipline == "Industrial" then
local tier = item.tier or ""
disciplineName = "Промышленность"
local cost = item.cost or ""
elseif discipline == "Experimental" then
local recipeUnlocks = item.recipeUnlocks or {}
disciplineName = "Экспериментальное"
elseif discipline == "CivilianServices" then
disciplineName = "Обслуживание персонала"
end
 
-- Загрузка данных из JSON
local data = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/research prototypes.json"):getContent())


local disciplineName = ""
local out = cssLink
if discipline == "Arsenal" then
local found = false  -- Флаг для отслеживания наличия элементов
disciplineName = "Арсенал"
elseif discipline == "Industrial" then
disciplineName = "Промышленность"
elseif discipline == "Experimental" then
disciplineName = "Экспериментальное"
elseif discipline == "CivilianServices" then
disciplineName = "Обслуживание персонала"
end


-- Формирование HTML
-- Обработка данных
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" id="' .. discipline .. '">'
out = out .. '<div class="research__images">[[Файл:' .. icon .. '.png|64px|центр|link=]]</div>'
out = out .. '<div class="research__images">[[Файл:' .. tech.icon .. '.png|64px|центр|link=]]</div>'
out = out .. '<div class="research__name">' .. name .. '[[Файл:' .. discipline .. '.png|16px|link=]]</div>'
out = out .. '<div class="research__name">' .. tech.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>Уровень: ' .. tech.tier .. '</div>'
out = out .. '<div class="research__category">' .. disciplineName .. '</div>'
out = out .. '<div class="research__technology">' .. disciplineName .. '</div>'
out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. cost .. '</span></div>'
out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.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(tech.recipeUnlocks) do
out = out .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' .. recipe .. '.png|' .. recipe .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' .. recipe .. '}}</li>'
out = out .. frame:preprocess('<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' .. recipe .. '.png|' .. recipe .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' .. recipe .. '}}</li>')
end
end
out = out .. '</ul>'
out = out .. '</ul>'
Строка 55: Строка 49:
out = out .. '</div>'
out = out .. '</div>'
end
end
end
if not found then
out = out .. '<div>Нет доступных технологий.</div>'
end
end



Текущая версия от 16:51, 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