Wiki League of Legends
Advertisement

La documentación para este módulo puede ser creada en Módulo:UniverseData/doc

-- <pre>

--[[
        Clave
            reference       cadena de carácteres
            author          cadena de carácteres
            artwork         cadena de carácteres
            starring        tabla
            mentioned       tabla
            region          tabla
            loretype        cadena de carácteres | Biografía, Cómic, Facción, Historia corta, Video
            duration        número
            description     cadena de carácteres
            previous        cadena de carácteres
            following       cadena de carácteres  | (nota: 'next' es una palabra reservada)
            au              cadena de carácteres  | si el universo alternativo se establece como "True" 
            status          cadena de carácteres  | si obsoleto se establece como "Obsoleto"
]]

--[[
		Used in
			Template:Lore banner		getBanner
			Template:Lore header		getCategories
			Template:More lore			getMore
			Template:Lore feature		getFeature
]]


local p = {}

local loreData  = mw.loadData('Módulo:UniverseData/data')
local lib       = require('Módulo:Feature')
local FN        = require('Módulo:Filename')
local builder   = require("Módulo:SimpleHTMLBuilder")


function p.loreTemplate(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	local loretypeArg = args["type"] or "Historia corta";
    local loreList = ''
    local lore = {}
 
    for x in pairs(loreData) do
        table.insert(lore, x)
    end
    table.sort(lore)
    
    for _, piece in pairs(lore) do
        local t = loreData[piece]
        local loretype = t.loretype or "N/A"
        local starring = t.starring
        local entry = ''
        
        if starring and (args["starring"] == nil or lib.string_to_bool(args["starring"])) then
            entry = '* [[' .. piece .. '|' .. piece .. ']] <small>('.. getChampions(starring) ..')</small>\n'
        else
            entry = '* [[' .. piece .. '|' .. piece .. ']]\n'
        end
        
        if loretype == loretypeArg then
            loreList = loreList .. entry
        end
    end
    return loreList
end

function p.getLoreTypes()
	local loreList = builder.create('ul')
    local lore = {}
    local res = {}
    
    for x in pairs(loreData) do
        table.insert(lore, x)
    end
    table.sort(lore)
 
    for _, piece in pairs(lore) do
        local t = loreData[piece]
        local loretype = t.loretype or "N/A"
        if not lib.in_array(res, loretype) then
			table.insert(res, loretype)
			loreList
            	:tag('li')
                	:tag('div')
                	:wikitext(loretype)
                	:done()
            	:done()
            	:newline()
        end
	end
    return loreList
end

function p.getBanner(frame) 
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return banner(args["title"], args["footer"] or "true")
end

function p.getFeature(frame) 
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return feature(args["title"], args["footer"] or "true")
end

function p.getCategories(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    
    local s = ""
    local t = loreData[args[1]] or loreData["Algo salió mal"]
    local loretype = t.loretype or "Información desprovista"
    local starring = t.starring or {}
    local mentioned = t.mentioned or {}
    local region = t.region or {}
    local canon = t.status or {}
    local count = 0
    
    if canon == "Obsoleto" then
        s = s .. "[[Categoría:Historias antiguas]]"
        s = s .. "<table style='' class='plainlinks ambox ambox-green'><tr><td class='ambox-image'>[[File:Goodbye, Friend! Emote.png|65px|link=]]</td><td class='ambox-info' style='line-height: 1.5em;'><i>\"¿Ya hemos terminado con esta realidad? ¿Hola? ¿Holaaa?\"</i><ul><li> Esta historia ya no se considera canon en el [[Runaterra Prime|lore principal]], pero existe aquí con fines históricos.</li></ul></td></tr></table>"
    else 
        if canon == "Debatible" then
            s = s .. "[[Categoría:Historias con canon debatible]]"
            s = s .. "<table style='' class='plainlinks ambox ambox-green'><tr><td class='ambox-image'>[[File:Oops Emote.png|65px|link=]]</td><td class='ambox-info' style='line-height: 1.5em;'><i>\"Paradojas. Odio a esos tipos.\"</i><ul><li> Esta historia ya no se considera canon en el [[Runaterra Prime|lore principal]], pero existe aquí como referencia.</li></ul></td></tr></table>"
        end
    end
    if t.au == "True" then
        s = s .. "<table style='' class='plainlinks ambox ambox-green'><tr><td class='ambox-image'>[[File:Howdy Emote.png|65px|link=]]</td><td class='ambox-info' style='line-height: 1.5em;'><i>\"La frontera es lo que quieras que sea.\"</i><ul><li> Esta historia tiene lugar en un [[Multiverso|universo]] diferente al [[Runaterra Prime|principal]].</li></ul></td></tr></table>"
        if loretype ~= nil then
            if loretype == "Video" then
                s = s .. "[[Categoría:Video del Universo Alterno]]"
            elseif loretype == "Comic" then
                s = s .. "[[Categoría:Cómic del Universo Alterno]][[Categoría:" .. args[1] .. "]]"
              elseif loretype == "Game" then
                s = s .. "[[Categoría:Juego del Universo Alterno]][[Categoría:" .. args[1] .. "]]"
            else
                s = s .. "[[Categoría:Universo Alterno " .. loretype .. "]]"
            end
        end
    else
        if region ~= nil then
            for i, region in pairs(region) do
                s = s .. "[[Categoría:Lore de " .. region .. "]]"
            end
        else
            s = s .. "[[Categoría:Lore sin configuración regional]]"
        end
        if loretype ~= nil then
            if loretype == "Video" then
                s = s .. "[[Categoría:Lore de videos]]"
            elseif loretype == "Comic" then
                s = s .. "[[Categoría:Cómic]][[Categoría:" .. args[1] .. "]]"
            elseif loretype == "Comic" then
                s = s .. "[[Categoría:Lore de juegos]][[Categoría:" .. args[1] .. "]]"
            else
                s = s .. "[[Categoría:" .. loretype .. "]]"
            end
        end
    end
    
    for i, champion in pairs(starring) do
        s = s .. "[[Categoría:Lore de " .. champion .. "]]"
        count = count + 1
    end
    
    for i, champion in pairs(mentioned) do
        s = s .. "[[Categoría:Lore de " .. champion .. "]]"
    end
    
    if count == 0 then
        s = s .. "[[Categoría: Lore sin campeón protagonista]]"
    end
    
    return s    
end

function p.getAuthor(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return loreData[args[1]].author or {"Autor desconocido"}
end

function p.getAuthorlist()
    local authors = {}
    local hash = {}
    local authorList = builder.create('ul')
 
    authorList:newline()
 
    for _, x in pairs(loreData) do
        if x.author ~= nil then
            for _, value in pairs(x.author) do
                if (not hash[value]) then
                    table.insert(authors, value)
                    hash[value] = true
                end
            end
        end
    end
    table.sort(authors)
 
    for _, author in pairs(authors) do
        authorList
            :tag('li')
                :wikitext('[[' .. author .. ']]')
                :done()
            :newline()
    end
 
    return authorList
end

function p.getReference(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return loreData[args[1]].reference or "https://universe.leagueoflegends.com/es_MX/"
end

function p.getArtwork(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return loreData[args[1]].artwork or "Bard promo 2.jpg"
end

function p.getLorelist(frame)
    local loreList = builder.create('ul')
    local lore = {}
 
    for x in pairs(loreData) do
        table.insert(lore, x)
    end
    table.sort(lore)
 
    for _, piece in pairs(lore) do
        local t = loreData[piece]
        local link = piece
        local name = piece
        local loretype = t.loretype or "N/A"
        
        if loretype == "Biografía" then
            link = t.starring[1]
        end
        
        loreList
            :tag('li')
                :tag('div')
                    :wikitext('[[' .. link .. '|' .. name .. ']] ('.. loretype ..')')
                :done()
            :done()
            :newline()
    end
    
    return loreList
end

function p.getMore(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
 
    local champion      = args[1]
    local article		= ""
    local bioList		= ""
    local loreList      = ""
    local mentionedList = ""
    local auList        = ""
    local removedList	= ""
    local lore          = {}
 
    for x in pairs(loreData) do
        table.insert(lore, x)
    end
    table.sort(lore)
 
    loreList = loreList .. "<h3>Campeón protagonista</h3>"
    for _, piece in pairs(lore) do
        local hit = false
        local t = loreData[piece]
 
        if t.starring ~= nil and t.loretype ~= "Facción" and t.loretype ~= "Universo" then
            for _, substarring in pairs(t.starring) do
                if substarring == champion then
                    hit = true
                end
            end
        end
        if hit == true then
        	if t.status == "Obsoleto" then
    			removedList = removedList .. banner(piece, "false")
			else
    			if t.au ~= "True" then
                	if t.loretype == "Biografía" then
                		bioList = bioList .. banner(piece, "false")
                	else 
                		loreList = loreList .. banner(piece, "false")
        			end
	            else
	                auList = auList .. banner(piece, "false")
	            end
			end
        end
    end
 
    for _, piece in pairs(lore) do
        local hit = false
        local t = loreData[piece]
 
        if t.mentioned ~= nil then
            for _, submentioned in pairs(t.mentioned) do
                if submentioned == champion then
                    hit = true
                end
            end
        end
        
        if hit == true then
            if t.status == "Obsoleto" then
    			removedList = removedList .. banner(piece, "false")
			else
    			if t.au ~= "True" then
                	mentionedList = mentionedList .. banner(piece, "false")
	            else
	                auList = auList .. banner(piece, "false")
	            end
			end
        end
 
    end
	
	if bioList ~= "" then
    	article = article .. "<h3>Biografía</h3>"
		article = article .. bioList
	end
	
	article = article .. loreList
	
    if mentionedList ~= "" then 
       article = article .. "\n<div class='va-collapsible-content mw-collapsible mw-collapsed' data-expandtext='show' data-collapsetext='hide'><h3>Campeón mencionado</h3><div class='va-collapsible-content mw-collapsible-content'>" .. mentionedList .. "</div></div>"
    end
 
    if auList ~= "" then 
       article = article .. "\n<div class='va-collapsible-content mw-collapsible mw-collapsed' data-expandtext='show' data-collapsetext='hide'><h3>Universos Alternos</h3><div class='va-collapsible-content mw-collapsible-content'>" .. auList .. "</div></div>"
    end
 
    if removedList ~= "" then 
       article = article .. "\n<div class='va-collapsible-content mw-collapsible mw-collapsed' data-expandtext='show' data-collapsetext='hide'><h3>Lore Obsoleto</h3><div class='va-collapsible-content mw-collapsible-content'>" .. removedList .. "</div></div>"
    end
    
    return article
end

function p.getRegionlore(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
 
    local loreList = ""
    local lore = {}
    local result = false
 
    for x in pairs(loreData) do
        table.insert(lore, x)
    end
    table.sort(lore)
 
    for _, piece in pairs(lore) do
        local hit = false
        local t = loreData[piece]
        
        if (t.region ~= nil) then
            for _, subregion in pairs(t.region) do
                if subregion == args[1] then
                    hit = true
                    result = true
                end
            end
        else 
            if args[1] == "Runaterra" then 
                hit = true
                result = true
            end
            
        end
    
        if hit == true then
            loreList = loreList .. banner(piece, "false")
        end
    end
 
    if result == false then 
       loreList = "No match found for " .. args[1] .. "."
    end
 
    return loreList .. "[[Categoría:Test]]"
end

function p.getDescription(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return loreData[args[1]].description or "Descripción no especificada."
end

function p.getDuration(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return loreData[args[1]].duration or "Duración no especificada."
end

function p.getLoretype(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return loreData[args[1]].loretype or "Tipo de historia no especificado."
end

function p.getMentioned(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    if loreData[args[1]].mentioned == nil then
        return "N/A"
    else
        return getChampions(loreData[args[1]].mentioned)
    end
end

function p.getRegion(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    if loreData[args[1]].region == nil then
        return "Runaterra"
    else
        return lib.tbl(loreData[args[1]].region)
    end
end

function p.getStarring(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    
    if loreData[args[1]].starring == nil then
        return "N/A"
    else
        return getChampions(loreData[args[1]].starring)
    end
end

function p.getTest(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return "{{User:Emptylord/Lore/Banner|" .. args[1] .. "}}"
end

function p.getPrevious(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return loreData[args[1]].previous or nil
end

function p.getFollowing(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return loreData[args[1]].following or nil
end

function p.getNarration(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

    return loreData[args[1]].narration or nil
end

-- local functions

function banner(name, footer)
    local piece = loreData[name] or loreData["Algo salió mal"]
    local s = ""

    local bName       = piece.altname     or name
    local artwork     = piece.artwork     or "Bard promo 2.jpg"
    local author      = piece.author      or {"Autor desconocido"}
    local reference   = piece.reference   or "https://universe.leagueoflegends.com/es_MX/"
    local link        = name
    local region      = "Runaterra"
    local duration    = piece.duration    or "0"
    local starring    = "N/A"
    local mentioned   = "N/A"
    local canon       = piece.status      or ""
    local loretype    = piece.loretype    or ""
    local description = piece.description or ""
    local narration   = piece.narration   or ""
    local narfooter   = footer            or "false"
    
    --if loretype == "Biografía" then link = piece.starring[1] end
    if piece.region ~= nil then region = piece.region[1] end
    if piece.starring ~= nil then starring = getChampions(piece.starring) end
    if piece.mentioned ~= nil then mentioned = getChampions(piece.mentioned) end
    if loretype == "Universo" then
    	link = link .. " (Universo)"
	end
    
    s = s .. "<div id='champinfo-container' style='width:100%; min-height: 290px; overflow:hidden; position:relative; font-size:14px; display:flex; z-index:0'>"
        --image
        s = s .. "<div class='FillImage' style='width:100%; height:100%; position:absolute; top: 0; left:0; opacity:0.2; z-index:0'>[[File:" .. artwork .."|link=]]</div>"
        --/image
        --edit
        s = s .. "<sup style='position: absolute; top: 1em; right: 1em; z-index:2'><span class='plainlinks'>[https://leagueoflegends.wikia.com/wiki/Módulo:UniverseData/data?action=edit Editar]</span> • [[:File:" .. artwork .."|Imagen]] • [" .. reference.. " Referencia]"
        if narfooter == "false" and narration ~= "" then 
            s = s .. "<br/>[[File:Actor.png|link=File:" .. narration .. "|24px]][[:File:" .. narration .. "|Escucha este artículo.]]"
        end
        s = s .. "</sup>"
        --/edit
        --content
        s = s .. "<div style='text-align:center; width: 500px; margin:auto; z-index:1'><div style='margin:3em 0'>"
            
            s = s .. "<p id='title' style='margin:1em 0 1em 0;'>[[File:" .. region .. " Crest icon.png|x56px|link=" .. region .."]]</p>"
            
            if loretype == "Historia corta" then
                if duration == "0" then
                    s = s .. "<p id='duration' style='margin:1em 0 0 0;'> Historia corta </p>"
                else
                    s = s .. "<p id='duration' style='margin:1em 0 0 0;'> Historia corta • " .. duration .." Minutos de lectura</p>"
                end
            else
                s = s .. "<p id='duration' style='margin:1em 0 0 0;'>" .. loretype .. "</p>"
            end
            
            if piece.previous ~= nil then
                s = s .. "<div style='position: absolute; top: 50%; left:1em; font-size:3em;'>[[" .. piece.previous .. "|⮜]]</div>"
            end
            
            s = s .. "<p id='title' style='font-size:250%; line-height:100%; margin:0;color:#c9aa71;'>[[" .. link .. "|" .. bName .."]]</p>"
            
            if loretype ~= "Video" then
                s = s .. "<p id='duration' style='margin:0 0 1em 0;'> Por "
                for i, value in ipairs(author) do
                    if i ~= 1 then
                        s = s  .. ", "
                    end
                    if value == "Autor desconocido" or value == "Numerosos creadores" then
                        s = s .. value
                    else 
                        s = s .. "[[" .. value .. "]]"
                    end
                end
                s = s .. "</p>"
            end
            
            if piece.following ~= nil then
                s = s .. "<div style='position: absolute; top: 50%; right: 1em; font-size:3em;'>[[" .. piece.following .. "|⮞]]</div>"
            end
            
            if loretype ~= "Biografía" then 
                s = s .. "<p id='blurb' style='margin:1em 0 1em 0; font-size: 89%; text-transform: initial;'>" .. description:gsub("//n", "<br/>") .."</p>"
            end
            
            if starring ~= nil then
                s = s .. "<p id='featured' style='margin:0 0 1em 0;'>Protagonizada por: " .. starring .. "</p>"
            end
            
            if mentioned ~= "N/A" then
                s = s .. "<p id='featured' style='margin:0 0 1em 0;'>Mencionado: " .. mentioned .. "</p>"
            end
        
        s = s .. "</div></div>"
        --/content
    s = s .. "</div>"
    if narfooter == "true" and narration ~= "" then 
        s = s .. "<div id='champinfo-container' style='position:relative; height:calc(36px + 2em); width: 100%; overflow:hidden; background:#010a13; text-align:center;'><div style='margin-top:1em;'>[[File:Actor.png|36px|link=File:" .. narration .. "]] [[:File:" .. narration .. "|ESCUCHA ESTE ARTÍCULO]]</div></div>"
    end

    return s
end

function feature(name, footer)
    local piece = loreData[name] or loreData["Algo salió mal"]
    local s = ""

    local bName       = piece.altname     or name
    local artwork     = piece.artwork     or "Bard promo 2.jpg"
    local author      = piece.author      or {"Autor desconocido"}
    local reference   = piece.reference   or "https://universe.leagueoflegends.com/es_MX/"
    local link        = name
    local region      = "Runaterra"
    local duration    = piece.duration    or "0"
    local starring    = "N/A"
    local mentioned   = "N/A"
    local canon       = piece.status      or ""
    local loretype    = piece.loretype    or ""
    local description = piece.description or ""
    local narration   = piece.narration   or ""
    local narfooter   = footer            or "false"
    
    if loretype == "Biografía" then link = piece.starring[1] end
    if piece.region ~= nil then region = piece.region[1] end
    if piece.starring ~= nil then starring = getChampions(piece.starring) end
    if piece.mentioned ~= nil then mentioned = getChampions(piece.mentioned) end
    
    s = s .. "<div id='champinfo-container' style='width:100%; min-height: 290px; overflow:hidden; position:relative; font-size:14px; color: #dddddd; display:flex;'><div style='margin:0 auto;'>"
        
        --edit
        s = s .. "<sup style='position: absolute; top: 1em; right: 1em; z-index:2'><span class='plainlinks'>[https://leagueoflegends.wikia.com/wiki/Módulo:UniverseData/data?action=edit Edit]</span> • [[:File:" .. artwork .."|Image]] • [" .. reference.. " Reference]"
        if narfooter == "false" and narration ~= "" then 
            s = s .. "<br/>[[File:Actor.png|link=File:" .. narration .. "|24px]][[:File:" .. narration .. "|Listen to this article.]]"
        end
        s = s .. "</sup>"
        --/edit
        --content
        s = s .. "<div style='text-align:center; width: 500px; z-index:1'><div style='margin:3em 0'>"
            
            s = s .. "<p id='title' style='margin:1em 0 1em 0;'>[[File:" .. region .. " Crest icon.png|x56px|link=" .. region .."]]</p>"
            
            if loretype == "Historia corta" then
                if duration == "0" then
                    s = s .. "<p id='duration' style='margin:1em 0 0 0;'> Historia corta </p>"
                else
                    s = s .. "<p id='duration' style='margin:1em 0 0 0;'> Historia corta • " .. duration .." Minutos de lectura</p>"
                end
            else
                s = s .. "<p id='duration' style='margin:1em 0 0 0;'>" .. loretype .. "</p>"
            end
            
            if piece.previous ~= nil then
                s = s .. "<div style='position: absolute; top: 50%; left:1em; font-size:3em;'>[[" .. piece.previous .. "|⮜]]</div>"
            end
            
            s = s .. "<p id='title' style='font-size:250%; line-height:100%; margin:0;color:#c9aa71;'>[[" .. link .. "|" .. bName .."]]</p>"
            
            if loretype ~= "Video" then
                s = s .. "<p id='duration' style='margin:0 0 1em 0;'> By "
                for i, value in ipairs(author) do
                    if i ~= 1 then
                        s = s  .. ", "
                    end
                    if value == "Autor desconocido" or value == "Numerosos creadores" then
                        s = s .. value
                    else 
                        s = s .. "[[" .. value .. "]]"
                    end
                end
                s = s .. "</p>"
            end
            
            if piece.following ~= nil then
                s = s .. "<div style='position: absolute; top: 50%; right: 1em; font-size:3em;'>[[" .. piece.following .. "|⮞]]</div>"
            end
            
            if loretype ~= "Biografía" then 
                s = s .. "<p id='blurb' style='margin:1em 0 1em 0; font-size: 89%; text-transform: initial;'>" .. description:gsub("//n", "<br/>") .."</p>"
            end
            
            if starring ~= nil and loretype ~= "Biografía" then
                s = s .. "<p id='featured' style='margin:0 0 1em 0;'>Protagonizada por: " .. starring .. "</p>"
            end
            
            if mentioned ~= "N/A" then
                s = s .. "<p id='featured' style='margin:0 0 1em 0;'>Mencionado: " .. mentioned .. "</p>"
            end
            
            --image
	        s = s .. "<div class='FillImage' style='width:25%; position:relative; margin: auto 0;'>[[File:" .. artwork .."|link=]]</div>"
	        --/image
        
        s = s .. "</div></div>"
        --/content
    s = s .. "</div></div>"
    if narfooter == "true" and narration ~= "" then 
        s = s .. "<div id='champinfo-container' style='position:relative; height:calc(36px + 2em); width: 100%; overflow:hidden; background:#010a13; text-align:center;'><div style='margin-top:1em;'>[[File:Actor.png|36px|link=File:" .. narration .. "]] [[:File:" .. narration .. "|ESCUCHA ESTE ARTÍCULO]]</div></div>"
    end

    return s
end

function getChampions(t)
    local s = ""
 
    local championtable  = {}
    for i, champion in pairs(t) do
        table.insert(championtable, champion)
    end
    table.sort(championtable)
 
    for i, champion in pairs(championtable) do
        if i ~= 1 then
            s = s  .. ", "
        end
            s = s .. "<span style='white-space:nowrap'>[[File:" .. champion .. "Square.png|20px|link=" .. champion .. "]] [[" .. champion .. "|" .. champion .."]]</span>"
    end
 
    return s
end

return p

-- </pre>
-- [[Categoría:Lua]]
Advertisement