League of Legends Wiki
Advertisement
League of Legends Wiki

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

-- <pre>
-- Используется для хранения и показа информации о персонажах TFT
-- Авторы: Ninjamask, Emptylord (eng League of Legends Wiki)
local p         = {}

local TFTUnits  = mw.loadData('Модуль:TFTUnitData/data')
local IL        = require("Модуль:ImageLink")
local lib       = require('Module:Feature')
local userError = require('Dev:User error')

function p.get(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    
    local get       = require ('Module:TFTUnitData/getter')
    local champname = args['champname']     or args[1]
    local set       = tonumber(args['set']) or tonumber(args[2])
    if(set == nil) then set = p.getLastSet{champname} end
    local datatype  = args['datatype']      or args[3]
    local output    = args['output']        or args[4] or nil
    
    local result = get[datatype](champname, set)
    
    if output ~= nil and type(result) == "table" then
        if output == "csv" then
            return lib.tbl_concat{result}
        elseif output == "custom" then 
            return frame:preprocess(lib.tbl_concat({result, prepend = args['prepend'], append = args['append'], separator = args['separator'], index = args["index"]}))
        elseif output == "template" then 
            return frame:preprocess(lib.tbl_concat{result, prepend = "{{" .. args['t_name'] .. "|", append = "}}", separator = args['separator']})
        end
    elseif (datatype == "active" or datatype == "passive") and result ~= nil then
        return frame:preprocess(result)
    elseif result == nil then
        return ""
    else
        return result
    end
end

function p.getSets(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
 
    local get       = require ('Module:TFTUnitData/getter')
    local champname = args['champname'] or args[1]
 
    return get["sets"](champname)
end

function p.getFirstSet(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    
    local champname = args['champname'] or args[1]
    
    for setnumber in pairs(TFTUnits[champname]) do
        firstSet = setnumber
        break;
    end
    
    return firstSet
end

function p.getLastSet(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    
    local champname = args['champname'] or args[1]
    if(TFTUnits[champname] == nil) then
        return userError("Чемпион " .. champname .. " не найден в Модуль:TFTUnitData/data")
    end
    local lastSet = 1
    
    for setnumber in pairs(TFTUnits[champname]) do
        if lastSet < setnumber then lastSet = setnumber end
    end
    
    return lastSet
end

function p.getTooltipSets(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    
    local champname = args['champname'] or args[1]
    local s         = ""
    
    for setnumber in pairs(TFTUnits[champname]) do
        s = s .. "TFT" .. setnumber .. ","
    end
    
    return s
end

function p.checkSetMembership(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	
	local champion = args["champion"] or args[1]
	local set = args["set"] or args[2]
	if(TFTUnits[champion][set]) then
		return "true"
	else
		return ""
	end
end

-- Создает строку категорий, которые относят чемпиона к особенностям TFT
function p.getChampionCategories(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local champion = args["champion"] or args[1]
	local set = tonumber(args["set"]) or tonumber(args[2])
	
	if(TFTUnits[champion] == nil) then return end
	if(TFTUnits[champion][set] == nil) then return end
	
	local origins = p.get{champion, set, "origin"}
	local originTable = {}
	local classes = p.get{champion, set, "class"}
	local classTable = {}
	
	for i, v in ipairs(origins) do
		table.insert(originTable, "[[Категория:TFT " .. v .. "]]")
	end
	
	for i, v in ipairs(classes) do
		table.insert(classTable, "[[Категория:TFT " .. v .. "]]")
	end
	
	local result = table.concat(originTable) .. "<br />" .. table.concat(classTable)
	
	return result
end

function p.checkRoster(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    
    local search     = args['champname'] or args[1]
    
    for champname in pairs(TFTUnits) do
        if champname == search then
            return true
        end
    end
    
    return false
end

function p.getRoster(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    
    local set = tonumber(args['set']) or tonumber(args[1]) 
    local currentSetTable = {}
    local resultTable = {}
    
    for k, v in pairs(TFTUnits) do
    	if(v[set] ~= nil) then
    		currentSetTable[k] = v
    	end
    end
    
    for k, v in lib.pairsByAlphabeticalKeys(currentSetTable) do
    	table.insert(resultTable, tostring(IL.championTFT{
    			["champion"] = k,
    			["set"] = set,
    			["size"] = "46px",
    			["text"] = "*none*",
    			["style"] = "white-space:inherit;"
    			}))
    end
    
    return table.concat(resultTable, "")
end

function p.getPortalRoster(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    local set        = tonumber(args['set']) or tonumber(args[1])
    
    local championTable = {}
    
    for k, v in pairs(TFTUnits) do
        if(v[set] ~= nil) then
        	championTable[k] = v[set]
        end
    end
    
    local flexNode = mw.html.create("div")
    flexNode
    	:css("display", "flex")
    	:css("flex-direction", "column")
    	:css("margin", "0 auto")
    	:css("padding", "5px")
    	:css("text-align", "center")
    	:done()
    	
    local rosterNode = mw.html.create("div")
    rosterNode
    	:addClass("centered-flex")
    	:done()
    
    for championKey, championValue in lib.pairsByAlphabeticalKeys(championTable) do
    	local championNode = mw.html.create("div")
    	mw.log(championKey)
    	championNode
    		:addClass("centered-grid-icon")
    		:cssText("padding: 0.5em; width: 100px;")
    		:wikitext(tostring(IL.championTFT{
    			["champion"] = championKey,
    			["set"] = set,
    			["size"] = "50px",
    			["separator"] = "<br />"
    		}))
    		:done()
    	rosterNode:node(championNode)
    end
    flexNode:node(rosterNode)
    return flexNode
end

function p.getGroup(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    
    local IL         = require('Модуль:ImageLink')
    local synergy    = args['synergy']       or args[1]
    local set        = tonumber(args['set']) or tonumber(args[2])
    local champtable = {}
    local roster     = {}
    
    synergy = _checkSpelling(synergy)
    
    for champname in pairs(TFTUnits) do
        table.insert(champtable, champname)
    end
    table.sort(champtable)
    
    for _, champname in pairs(champtable) do
        for dataset, v in pairs(TFTUnits[champname]) do
            if dataset == set then
                for _, classname in pairs(v.class) do
                    if classname == synergy then
                        table.insert(roster, tostring(IL.championTFT{
                            ['champion'] = champname,
                            ['set'] = set,
                            ['size'] = "46px",
                            ['text'] = "*none*",
                            ['style'] = "white-space:inherit;"
                        }))
                    end
                end
                for _, originname in pairs(v.origin) do
                    if originname == synergy then
                        table.insert(roster, tostring(IL.championTFT{
                            ['champion'] = champname,
                            ['set'] = set,
                            ['size'] = "46px",
                            ['text'] = "*none*",
                            ['style'] = "white-space:inherit;"
                        }))
                    end
                end
            end
        end
    end
    
    return table.concat(roster, "")
end

-- Создает подменю со ссылками на воплощения чемпиона в разных сезонах TFT
-- Создано на основе Шаблон:Подстраницы чемпиона
function p.getChampionSubMenu(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	
	local champion = args["champion"] or args[1]
	local SET_ICONS = {
		[1]   = "TFT set icon.png",
		[2]   = "Elements TFT set_icon.png",
		[3]   = "Galaxies TFT set icon.png",
		[3.5] = "Galaxies TFT set icon.png",
		[4]   = "Fates TFT set icon.png",
		[4.5] = "Fates TFT set icon.png",
		[5]   = "Reckoning TFT set icon.png",
		[5.5]   = "Reckoning TFT set icon.png"
	}
	
	if(TFTUnits[champion] == nil) then
		userError("Чемпион " .. champion .. " не найден в Модуль:TFTUnitData/data")
	end
	
	local subMenuNode = mw.html.create("div")
	subMenuNode
		:addClass("league-font")
		:cssText("width:100%; margin-bottom: 1em;")
		:newline()
		:done()
	
	for i, v in _setsIterator(TFTUnits[champion]) do
		mw.log(i)
		local icon = SET_ICONS[i]
		local subMenuItem = mw.html.create("div")
		subMenuItem:addClass("submenu-item")
		if(icon ~= nil) then
			subMenuItem:wikitext(mw.ustring.format(
				"[[File:%s|20px|link=%s]]&nbsp;[[%s|Сезон %s]]",
				icon,
				champion .. "/TFT/Сезон " .. tostring(i),
				champion .. "/TFT/Сезон " .. tostring(i),
				tostring(i)))
		else
			subMenuItem:wikitext(mw.ustring.format(
				"[[%s|Сезон %d]]",
				champion .. "/TFT/Сезон " .. tostring(i),
				i))
		end
		subMenuNode:node(subMenuItem):newline()
	end
	return subMenuNode
end

function _checkSpelling(trait)
    if(trait == "Звездолёт") then return "Звездолет" end
    if(trait == "Космический пират") then return "Космопират" end
    if(trait == "Защитник") then return "Заступник" end
    if(trait == "Пилот робота") then return "Пилот меха" end
    if(trait == "Звёздный защитник") then return "Звездный защитник" end
    if(trait == "Тёмная звезда") then return "Темная Звезда" end
    if(trait == "Темная звезда") then return "Темная Звезда" end
    if(trait == "Наёмник") then return "Наемник" end
    return trait
end

function _setsIterator(t)
	local main = require("Модуль:Maintenance data")
	local maxSet = tonumber(main.main{"TFTSet"})
	local current = 0
	
	return function()
			while(current < maxSet) do
				if(current < 3) then
					current = current + 1
				else
					current = current + 0.5
				end
				if(t[current] ~= nil) then
					return current, t[current]
				end
			end
		end
end

return p
-- </pre>
-- [[Category:Lua]]
Advertisement