Module:UniverseData

--

--       Key            artwork         string            starring        table            mentioned       table            region          table            loretype        string            duration        number            description     string -- local p = {}

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

function banner(name, piece) local s = "" local artwork = piece.artwork or "MSI 2018 Promo 01.jpg" local link = name local region = "Runeterra" local duration = piece.duration or "N/A" 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 .. " "            if loretype == "Short Story" then s = s .. " Short Story • " .. duration .." Minute Read " else s = s .. "" .. loretype .. " "           end s = s .. "" .. name .." " if loretype ~= "Biography" then s = s .. "" .. description .." " 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 .. " " 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 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, t)       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, t)       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 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 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 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

return loreData[args[1]].region 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 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

-- --