Module:UniverseData

--

--       Key            author          string            artwork         string            starring        table            mentioned       table            region          table            loretype        string            duration        number            description     string            previous        string            following       string ('next' is a reserved word) -- local p = {}

local loreData = mw.loadData('Module:UniverseData/data') local lib      = require('Module:Feature') local FN       = require('Module:Filename')

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[1]) 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["Something Went Wrong"] local loretype = t.loretype or "Missing information" s = s .. ""   for i, champion in pairs(t.starring) do        s = s .. ""   end for i, champion in pairs(t.mentioned) do       s = s .. ""   end for i, region in pairs(t.region) do       s = s .. ""   end return s   end

function banner(name) local piece = loreData[name] or loreData["Something Went Wrong"] local s = "" local artwork = piece.artwork or "Bard promo 2.jpg" local author = piece.author or "Unknown Author" local link = name local region = "Runeterra" local duration = piece.duration or "0" local starring = "N/A" local mentioned = "N/A" local loretype = piece.loretype or "" local description = piece.description or "" if loretype == "Biography" 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 .. "" --image s = s .. " " --/image --edit s = s .. "Edit " --/edit --content s = s .. " "            s = s .. " " if loretype == "Short Story" then if duration == "0" then s = s .. " Short Story " else s = s .. " Short Story • " .. duration .." Minute Read " end else s = s .. "" .. loretype .. " "           end if piece.previous ~= nil then s = s .. " ⯇ " end s = s .. "" .. name .." " s = s .. " By " .. author .." " if piece.following ~= nil then s = s .. " ⯈ " end if loretype ~= "Biography" then s = s .. "" .. description:gsub("//n", " ") .." " end if starring ~= nil and loretype ~= "Biography" then s = s .. "Starring: " .. starring .. " "           end if mentioned ~= "N/A" then s = s .. "Mentioned: " .. mentioned .. " "           end s = s .. " "        --/content s = s .. " "

return s 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.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 "Unknown Author" end

function p.getLorelist(frame) local loreList = mw.html.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 if t.loretype == "Biography" then link = t.starring[1] end loreList :tag('li') :tag('div') :wikitext('' .. name .. ' ('.. t.loretype ..')') :done :done :newline end return loreList end

function p.getChampionlore(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.starring ~= nil) then if type(t.starring) == "table" then for _, substarring in pairs(t.starring) do                   if substarring == args[1] then hit = true result = true end end else if t.starring == args[1] then hit = true result = true end end end if hit == true then loreList = loreList .. banner(piece) end end for _, piece in pairs(lore) do       local hit = false local t = loreData[piece] if (t.mentioned ~= nil) then if type(t.mentioned) == "table" then for _, submentioned in pairs(t.mentioned) do                   if submentioned == args[1] then hit = true result = true end end else if t.mentioned == args[1] then hit = true result = true end end end if hit == true then loreList = loreList .. banner(piece) end end if result == false then loreList = "No match found for " .. args[1] .. "."   end return loreList 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 if type(t.region) == "table" then for _, subregion in pairs(t.region) do                   if subregion == args[1] then hit = true result = true end end else if t.region == args[1] then hit = true result = true end end else if args[1] == "Runeterra" then hit = true result = true end end if hit == true then loreList = loreList .. banner(piece, t)       end end if result == false then loreList = "No match found for " .. args[1] .. "."   end return loreList 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 "Description not specified." 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 "Duration not specified." 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 "Loretype not specified." 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 "Runeterra" else return table.tostring(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 "" 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 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 .. ", " .. champion .. " " else s = s .. " " .. champion .. " " end end return s end

-- helper functions function table.val_to_str ( v ) if "string" == type( v ) then v = string.gsub( v, "\n", "\\n" ) if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then return "'" .. v .. "'"   end return '"' .. string.gsub(v,'"', '\\"' ) .. '"' else return "table" == type( v ) and table.tostring( v ) or     tostring( v ) end end function table.key_to_str ( k ) if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then return k else return "[" .. table.val_to_str( k ) .. "]" end end function table.tostring( tbl ) local result, done = {}, {} for k, v in ipairs( tbl ) do   table.insert( result, table.val_to_str( v ) ) done[ k ] = true end for k, v in pairs( tbl ) do   if not done[ k ] then table.insert( result,       table.key_to_str( k ) .. "=" .. table.val_to_str( v ) ) end end return "{" .. table.concat( result, "," ) .. "}" end

return p

-- --