Модуль:Tools

Версия от 05:06, 22 сентября 2024; JustPlayer (обсуждение | вклад)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)

local p = {}

local lib         = require('Module:Feature')
local icons_data  = require ('Module:IconData/alliances')

function p.getTodoTable(frame)
	local tableNode = mw.html.create('table')
    tableNode
        :addClass('pc-block service-table')
        :cssText('width: 100%; display: table; margin: 0 auto; text-align: center;')
        :newline()
    
    tableNode
        :tag('tr')
            :css('white-space', 'nowrap')
            :tag('th')
                :wikitext('Задача')
                :done()
            :tag('th')
                :wikitext('Описание')
                :done()
            :tag('th')
                :wikitext('Ответственный')
                :done()
            :tag('th')
                :wikitext('Статус')
                :done()
            :done()
            
    local list     = mw.loadData('Module:Tools/todo')
    local statuses = mw.loadData('Module:Tools/todo/statuses')
    local member   = ""
    local status   = ""
    for k, v in ipairs(list) do
    	if v[3] == "" or v[3] == nil then
    		member = "Все желающие"
    	else
    		member = mw.ustring.format('[[Участник:%s|%s]]', v[3], v[3])
    	end
    	
    	if v[4] == 1 then
    		status = mw.ustring.format('{{Цвет|обы|%s}}', statuses[v[4]])
    	elseif v[4] == 2 then
    		status = mw.ustring.format('{{Цвет|жел|%s}}', statuses[v[4]])
    	elseif v[4] == 3 then
    		status = mw.ustring.format('{{Цвет|зел|%s}}', statuses[v[4]])
    	end
    	
        local rowNode = mw.html.create('tr')
        rowNode
            :tag('td')
            	:css('color', '#25a6f2')
                :wikitext(mw.ustring.format('%s', v[1]))
                :done()
            :tag('td')
            	:css('text-align', 'left')
                :wikitext(mw.ustring.format('%s', v[2]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('%s', member))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('%s', status))
                :done()
            :done()
        tableNode:node(rowNode):newline()
    end
    
    return frame:preprocess(tostring(tableNode))
end

function p.getNoveltyHeroes(frame)
	local divNode = mw.html.create('div')
	local str = ""
	local i = 0
	
    divNode
        :addClass('mainpage-card__body mainpage-card__content content-rows')
        :newline()
        
    local data = mw.loadData('Module:Tools/novelty')
    
    for k, v in lib.pairsByAlphabeticalKeys(data['heroes'], function(a, b) return a > b end) do
    	i = i + 1
		if i < 6 then
			str = str .. mw.ustring.format('{{SimpleIconHero|hero=%s|size=60px|tooltip=true}}', v[1])
		end
    end

	divNode
		:wikitext(mw.ustring.format('%s', str))
		:done()
        
    return frame:preprocess(tostring(divNode))
end

function p.getFullNoveltyHeroes(frame)
	local tableNode = mw.html.create('table')
	
    tableNode
        :addClass('custom-table active-hover')
        :cssText('width: 100%; display: table; margin: 0 auto; text-align: center;')
        :newline()
        
    tableNode
        :tag('tr')
            :css('white-space', 'nowrap')
            :tag('th')
                :wikitext('Дата')
                :done()
            :tag('th')
                :wikitext('Имя героя')
                :done()
            :tag('th')
                :wikitext('Иконка')
                :done()
            :tag('th')
                :wikitext('Раса')
                :done()
            :tag('th')
                :wikitext('Класс')
                :done()
        	:tag('th')
                :wikitext('Альянс')
                :done()
            :done()
    
    local data        = mw.loadData('Module:Tools/novelty')
    local data_heroes = mw.loadData('Module:HeroData/data')
    local races       = mw.loadData('Module:HeroData/races')
    local classes     = mw.loadData('Module:HeroData/classes')
    local alliances   = mw.loadData('Module:HeroData/alliances')
    
    local icon        = ""
    
	for k, v in lib.pairsByAlphabeticalKeys(data['heroes'], function(a, b) return a > b end) do
		
		if data_heroes[v[1]]['race'] ~= nil then
			race = races[data_heroes[v[1]]['race']]
		else
			race = "-"
		end
		
		if data_heroes[v[1]]['class'] ~= nil then
			class = classes[data_heroes[v[1]]['class']]
		else
			class = "-"
		end
		
		if data_heroes[v[1]]['alliance'] ~= nil then
			alliance = alliances[data_heroes[v[1]]['alliance']]
		else
			alliance = "-"
		end
		
		if icons_data[alliance] ~= nil then
			icon = icons_data[alliance]
		else
			return "-"
		end
	
		local rowNode = mw.html.create('tr')
		
        rowNode
            :tag('td')
                :wikitext(mw.ustring.format('%s', v[2]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('[[%s]]', v[1]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('{{SimpleIconHero|hero=%s|size=45px}}', v[1]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('[[:Категория:%s (раса)|%s]]', race, race))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('[[:Категория:%s (класс)|%s]]', class, class))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('[[Файл:%s|%s|link=:Категория:%s (альянс)]]', icon, "45px", alliance))
                :done()
            :done()
        tableNode:node(rowNode):newline()
	end
        
    return frame:preprocess(tostring(tableNode))
end

function p.getNoveltyBosses(frame)
	local divNode = mw.html.create('div')
	local str = ""
	local i = 0
	
    divNode
        :addClass('mainpage-card__body mainpage-card__content content-rows')
        :newline()
        
    local data = mw.loadData('Module:Tools/novelty')
    
	for k, v in lib.pairsByAlphabeticalKeys(data['bosses'], function(a, b) return a > b end) do
    	i = i + 1
		if i < 6 then
			str = str .. mw.ustring.format('{{SimpleIconBoss|boss=%s|size=60px|border=3px ridge #3d8ac2|tooltip=true}}', v[1])
		end
	end

	divNode
		:wikitext(mw.ustring.format('%s', str))
		:done()
        
    return frame:preprocess(tostring(divNode))
end

function p.getFullNoveltyBosses(frame)
	local tableNode = mw.html.create('table')
	
    tableNode
        :addClass('custom-table active-hover')
        :cssText('width: 100%; display: table; margin: 0 auto; text-align: center;')
        :newline()
        
    tableNode
        :tag('tr')
            :css('white-space', 'nowrap')
            :tag('th')
                :wikitext('Дата')
                :done()
            :tag('th')
                :wikitext('Имя босса')
                :done()
            :tag('th')
                :wikitext('Иконка')
                :done()
            :tag('th')
                :wikitext('Раса')
                :done()
            :tag('th')
                :wikitext('Здоровье')
                :done()
        	:tag('th')
                :wikitext('Очки осады')
                :done()
            :done()
    
    local data        = mw.loadData('Module:Tools/novelty')
    local data_bosses = mw.loadData('Module:BossData/data')
    local races       = mw.loadData('Module:HeroData/races')
    
    local icon        = ""
    
	for k, v in lib.pairsByAlphabeticalKeys(data['bosses'], function(a, b) return a > b end) do
		
		if data_bosses[v[1]]['race'] ~= nil then
			race = races[data_bosses[v[1]]['race']]
		else
			race = "-"
		end
	
		local rowNode = mw.html.create('tr')
		
        rowNode
            :tag('td')
                :wikitext(mw.ustring.format('%s', v[2]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('[[%s/босс|%s]]', v[1], data_bosses[v[1]]['name']))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('{{SimpleIconBoss|boss=%s|size=45px|border=3px ridge #3d8ac2}}', v[1]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format(mw.ustring.format(lib.ternary(data_bosses[v[1]]['race'] == nil, "N/A", '[[:Категория:%s (раса)|%s]]'), race, race)))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('<div class="boss-hp" style="width: fit-content; margin: 0 auto;">%s</div>', lib.comma_value(data_bosses[v[1]]['hp'])))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('<div style="display: flex;">{{Очки осады}} <span class="score">%s</span></div>', data_bosses[v[1]]['points']))
                :done()
            :done()
        tableNode:node(rowNode):newline()
	end
        
    return frame:preprocess(tostring(tableNode))
end

function p.getNoveltyItems(frame)
	local divNode = mw.html.create('div')
	local str = ""
	local i = 0
	
    divNode
        :addClass('mainpage-card__body mainpage-card__content content-rows')
        :newline()
        
    local data = mw.loadData('Module:Tools/novelty')
    
	for k, v in lib.pairsByAlphabeticalKeys(data['items'], function(a, b) return a > b end) do
    	i = i + 1
		if i < 6 then
			str = str .. mw.ustring.format('{{SimpleIconItem|item=%s|size=60px|tooltip=true}}', v[1])
		end
	end

	divNode
		:wikitext(mw.ustring.format('%s', str))
		:done()
        
    return frame:preprocess(tostring(divNode))
end

function p.getFullNoveltyItems(frame)
	local tableNode = mw.html.create('table')
	
    tableNode
        :addClass('custom-table active-hover')
        :cssText('width: 100%; display: table; margin: 0 auto; text-align: center;')
        :newline()
        
    tableNode
        :tag('tr')
            :css('white-space', 'nowrap')
            :tag('th')
                :wikitext('Дата')
                :done()
            :tag('th')
                :wikitext('Название предмета')
                :done()
            :tag('th')
                :wikitext('Иконка')
                :done()
            :tag('th')
                :wikitext('Описание')
                :done()
            :done()
    
    local data        = mw.loadData('Module:Tools/novelty')
    local data_items  = mw.loadData('Module:ItemData/data')
    
    local icon        = ""
    
	for k, v in lib.pairsByAlphabeticalKeys(data['items'], function(a, b) return a > b end) do
	
		local rowNode = mw.html.create('tr')
		
        rowNode
            :tag('td')
                :wikitext(mw.ustring.format('%s', v[2]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('[[%s]]', v[1]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('{{SimpleIconItem|item=%s|size=45px}}', v[1]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('<span style="font-style: italic; color: #649ec0;">%s</span>', data_items[v[1]]['description']))
                :done()
            :done()
        tableNode:node(rowNode):newline()
	end
        
    return frame:preprocess(tostring(tableNode))
end

function p.getNoveltyRecipes(frame)
	local divNode = mw.html.create('div')
	local str = ""
	local i = 0
	
    divNode
        :addClass('mainpage-card__body mainpage-card__content content-rows')
        :newline()
        
    local data = mw.loadData('Module:Tools/novelty')
  
	for k, v in lib.pairsByAlphabeticalKeys(data['recipes'], function(a, b) return a > b end) do
    	i = i + 1
		if i < 6 then
			str = str .. mw.ustring.format('{{SimpleIconItem|item=%s|size=60px|tooltip=true}}', v[1])
		end
	end

	divNode
		:wikitext(mw.ustring.format('%s', str))
		:done()
        
    return frame:preprocess(tostring(divNode))
end

function p.getFullNoveltyRecipes(frame)
	local tableNode = mw.html.create('table')
	
    tableNode
        :addClass('custom-table active-hover')
        :cssText('width: 100%; display: table; margin: 0 auto; text-align: center;')
        :newline()
        
    tableNode
        :tag('tr')
            :css('white-space', 'nowrap')
            :tag('th')
                :wikitext('Дата')
                :done()
            :tag('th')
                :wikitext('Название предмета')
                :done()
            :tag('th')
                :wikitext('Иконка')
                :done()
            :tag('th')
                :wikitext('Описание')
                :done()
            :done()
    
    local data          = mw.loadData('Module:Tools/novelty')
    local data_items    = mw.loadData('Module:ItemData/data')
    
    local icon        = ""
    
	for k, v in lib.pairsByAlphabeticalKeys(data['recipes'], function(a, b) return a > b end) do
	
		local rowNode = mw.html.create('tr')
		
        rowNode
            :tag('td')
                :wikitext(mw.ustring.format('%s', v[2]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('[[%s]]', v[1]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('{{SimpleIconItem|item=%s|size=45px}}', v[1]))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('<span style="font-style: italic; color: #649ec0;">%s</span>', data_items[v[1]]['description']))
                :done()
            :done()
        tableNode:node(rowNode):newline()
	end
        
    return frame:preprocess(tostring(tableNode))
end

function p.getEventTodayInGame(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	local get       = require ('Module:Tools/today/getter')
	local data      = mw.loadData('Module:Tools/today')
	local event     = data["event"]
	local divNode = mw.html.create('div')
	local str       = ""
	
	str = str .. mw.ustring.format('{{SimpleIconHero|hero=%s|size=45px}}', get["event_hero"](event))
	
	for _, v in ipairs(get["event_heroes"](event)) do
		str = str .. mw.ustring.format('{{SimpleIconHero|hero=%s|size=45px}}', v)
	end
	
	divNode
        :addClass('mainpage-card__body mainpage-card__content content-cols')
        :newline()
        
    divNode
    	:tag('div')
    		:addClass('mainpage-card__content--header')
    		:wikitext('Событие')
    		:done()
    	:tag('div')
    		:addClass('mainpage-card__content--label')
    		:wikitext(mw.ustring.format('[[Файл:%s|16px|link=]] [[События/%s|%s]]', get["event_icon"](event), get["event_name"](event), get["event_name"](event)))
    		:done()
    	:tag('div')
    		:addClass('mainpage-card__content--heroes')
    		:wikitext(mw.ustring.format('%s', str))
    		:done()
    	divNode:newline()
    
    return frame:preprocess(tostring(divNode))
end

function p.getSiegeTodayInGame(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	local get       = require ('Module:Tools/today/getter')
	local data      = mw.loadData('Module:Tools/today')
	local servers   = mw.loadData('Module:Tools/servers')
	local sieges    = data["siege"]
	local divNode   = mw.html.create('div')
	local str       = {"", "", "", "", "", "", "", "", "", "", "", "", "", ""}
	local str2      = {"", "", "", "", "", "", "", "", "", "", "", "", "", ""}
	local i         = 1
	
	divNode
        :addClass('mainpage-card__body mainpage-card__content content-cols')
        :newline()
        
    local divNode2 = mw.html.create('div')
    divNode2
    	:addClass('owl-carousel owl-theme siege-carousel')
		divNode:node(divNode2):newline()
        
    for k, v in ipairs(sieges) do
    	if k == i then
    		if v ~= 9 then
				str[i] = str[i] .. mw.ustring.format('{{SimpleIconHero|hero=%s|size=45px}}', get["siege_hero"](v))

				for _, v1 in ipairs(get["siege_heroes"](v)) do
					str[i] = str[i] .. mw.ustring.format('{{SimpleIconHero|hero=%s|size=45px}}', v1)
				end
			else
				str[i] = str[i] .. mw.ustring.format('{{SimpleIconItem|item=%s|size=45px}}{{SimpleIconItem|item=%s|size=45px}}', "Сундук темного короля ур.5", "Сундук темного короля ур.6")
			end
			
			for k2, v2 in ipairs(servers) do
				if k2 == i then
					str2[i] = str2[i] .. mw.ustring.format('%s', v2)
				end
			end
		    
		    local divNode3 = mw.html.create('div')
		    divNode3
		    	:tag('div')
		    		:addClass('mainpage-card__content--header')
		    		:wikitext('Осада')
		    		:done()
		    	:tag('div')
		    		:addClass('mainpage-card__content--label')
		    		:wikitext(mw.ustring.format('[[Файл:%s|16px|link=]] [[Осады/%s|%s]]', get["siege_icon"](v), get["siege_name"](v), get["siege_name"](v)))
		    		:done()
		    	:tag('div')
		    		:addClass('mainpage-card__content--heroes')
		    		:wikitext(mw.ustring.format('%s', str[i]))
		    		:done()
		        :tag('div')
		    		:addClass('mainpage-card__content--footer')
		    		:wikitext(mw.ustring.format('%s', str2[i]))
		    		:done()
		    divNode2:node(divNode3):newline()
		    
		    i = i + 1
		end
	end
    
    return frame:preprocess(tostring(divNode))
end

function p.getDragondraftTodayInGame(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	local get         = require ('Module:Tools/today/getter')
	local data        = mw.loadData('Module:Tools/today')
	local dragondraft = data["dragondraft"]
	local divNode     = mw.html.create('div')
	local str         = ""
	
	str = str .. mw.ustring.format('{{SimpleIconHero|hero=%s|size=45px}}', get["dragondraft_hero"](dragondraft))
	
	for _, v in ipairs(get["dragondraft_heroes"](dragondraft)) do
		str = str .. mw.ustring.format('{{SimpleIconHero|hero=%s|size=45px}}', v)
	end
	
	divNode
        :addClass('mainpage-card__body mainpage-card__content content-cols')
        :newline()
        
    divNode
    	:tag('div')
    		:addClass('mainpage-card__content--header')
    		:wikitext('Драконий Драфт')
    		:done()
    	:tag('div')
    		:addClass('mainpage-card__content--label')
    		:wikitext(mw.ustring.format('[[Файл:%s|16px|link=]] [[Драконий Драфт/%s|%s]]', get["dragondraft_icon"](dragondraft), get["dragondraft_link"](dragondraft), get["dragondraft_name"](dragondraft)))
    		:done()
    	:tag('div')
    		:addClass('mainpage-card__content--heroes')
    		:wikitext(mw.ustring.format('%s', str))
    		:done()
    	divNode:newline()
    
    return frame:preprocess(tostring(divNode))
end

function p.getLabyrinthTodayInGame(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	local get        = require ('Module:Tools/today/getter')
	local data       = mw.loadData('Module:Tools/today')
	local servers    = mw.loadData('Module:Tools/servers')
	local labyrinths = data["labyrinth"]
	local divNode    = mw.html.create('div')
	local str        = {"", "", "", "", "", "", "", "", "", "", "", "", "", ""}
	local str2       = {"", "", "", "", "", "", "", "", "", "", "", "", "", ""}
	local i          = 1
	
	divNode
        :addClass('mainpage-card__body mainpage-card__content content-cols')
        :newline()
        
    local divNode2 = mw.html.create('div')
    divNode2
    	:addClass('owl-carousel owl-theme siege-carousel')
		divNode:node(divNode2):newline()
        
    for k, v in ipairs(labyrinths) do
    	if k == i then
			str[i] = str[i] .. mw.ustring.format('{{SimpleIconItem|item=Осколки: %s|size=45px}}', get["labyrinth_hero"](v))

			if v == 9 then
				str[i] = str[i] .. mw.ustring.format('{{SimpleIconItem|item=%s|size=45px}}', "Сундук темного короля ур.5")
			end
			
			str[i] = str[i] .. mw.ustring.format('{{SimpleIconHero|hero=%s|size=45px}}', get["labyrinth_hero_small"](v))
			
			for k2, v2 in ipairs(servers) do
				if k2 == i then
					str2[i] = str2[i] .. mw.ustring.format('%s', v2)
				end
			end
		    
		    local divNode3 = mw.html.create('div')
		    divNode3
		    	:tag('div')
		    		:addClass('mainpage-card__content--header')
		    		:wikitext('Лабиринт')
		    		:done()
		    	:tag('div')
		    		:addClass('mainpage-card__content--label')
		    		:wikitext(mw.ustring.format('[[Файл:%s|20px|link=]] [[Лабиринт/%s|%s]]', get["labyrinth_icon"](v), get["labyrinth_name"](v), get["labyrinth_name"](v)))
		    		:done()
		    	:tag('div')
		    		:addClass('mainpage-card__content--heroes')
		    		:wikitext(mw.ustring.format('%s', str[i]))
		    		:done()
		        :tag('div')
		    		:addClass('mainpage-card__content--footer')
		    		:wikitext(mw.ustring.format('%s', str2[i]))
		    		:done()
		    divNode2:node(divNode3):newline()
		    
		    i = i + 1
		end
	end
    
    return frame:preprocess(tostring(divNode))
end

return p